Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: oBFusCATed on June 18, 2009, 09:37:02 pm

Title: Extreme slowness in squirrel script
Post by: oBFusCATed on June 18, 2009, 09:37:02 pm
Here are some variants of a script that is very slow in squirrel

version 1:
Code
    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:
Code
    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:
Code
    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:
Code
    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:
Code
            {
                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++