News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Extreme slowness in squirrel script

Started by oBFusCATed, June 18, 2009, 09:37:02 PM

Previous topic - Next topic

oBFusCATed

Here are some variants of a script that is very slow in squirrel

version 1:

    local result = _T("{ ");
    for(local item_ = 0; item_ < 10000; item_ += 1)
    {
        result += _T("[");
//        result += _T("-----");
        result += item_;
        result += _T("] = 10\n");
    }
    result += _T(" }");
    return result;

time: 28,792 seconds

uncommenting the line "//        result += _T("-----");" slows this even more to 44+ seconds

version 2:

    local result = "{ ";
    for(local item_ = 0; item_ < 10000; item_ += 1)
    {
        result += "[";
        result += "-----";
        result += item_;
        result += "] = 10\n";
    }
    result += " }";
    return _T(result);

time: 0,648 seconds

commenting "result += "-----";" drops the time to 0,336 seconds

version 3:

    local result = _T("{ ");
    for(local item_ = 0; item_ < 10000; item_ += 1)
    {
        result += _T("[") + item_ + _T("] = 10\n");
    }
    result += _T(" }");
    return result;

time: 0,376 seconds

version 4:

    local result = "{ ";
    for(local item_ = 0; item_ < 10000; item_ += 1)
    {
        result += "[" + item_ + "] = 10\n";
    }
    result += " }";
    return _T(result);

time:  0,124 seconds

and the c++ version:

            {
                wxStopWatch sw;
                wxString test;
                for(int ii = 0; ii < 10000; ++ii)
                {
                    test += _T("[");
                    test += wxString::Format(_T("%d"), ii);
                    test += _T("] = 100000");
                }
                Manager::Get()->GetLogManager()->Log(wxString::Format(_T("testing takes: %3.3lf seconds"),
                                                                      sw.Time() / 1000.0));
            }

time: 0.005 sec

Does someone know how this scripts can be made faster (less than 0.050 seconds should be the target, I think)?
If not I suppose the only solution is to make a c++ function (DoHeavyLifting(some, params)) and export it to squirrel?

p.s. I'm using C::B compiled from C::B and I've checked the -O2 option in the project -> build options -> root target
p.s.s. pc spec gentoo linux amd64, q6600 @ 3.4ghz
p.s.s.s. timing of the squirrel funcs include the calling of the function from c++

(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]