After removing type checking and the "[SCRIPT] Number of rows: 5" print (because others didn't do it - it's supposed to be a fair test after all), here's what I got:
[USR] Total iterations: 200
[USR] Average for Flake: 21111 us
[USR] Average for Doom: 21637 us
[USR] Average for SLC: 21889 usI've noticed that the slowest part of this is
print, and am quite sure that if we do this with variables instead, we'll reduce the total time by a factor of 10 or something.
200 iterations took about 20 seconds on my PC.
After replacing all
print calls with an NOP instead, here is what I got (I used 500 iterations this time because it as a whole is much faster and this time the results aren't as reliable individually as they were before):
[USR] Total iterations: 500
[USR] Average for Flake: 307 us
[USR] Average for Doom: 308 us
[USR] Average for SLC: 326 usHaven't quite replaced print with variables - rather, with a NOP, but it's still a reduction of not by a factor of 10 like I was expecting but a factor of almost 100.
function kprint(val)
{
}
function PrintRowz(num)
{
//kprint("Number of rows: " + num);
//if (typeof(num) != "integer" || num < 1) return kprint("Rejected");
local Repeat = function (str, num)
{
local ret = "";
for (local i = 0; i < num; ++i) ret += str;
return ret;
}
for (local i = 0; i < num; ++i)
{
kprint(Repeat(".", num - i) + Repeat("*", i));
}
}
function Generate(l) for (local f = function(p, l, x = 0, b = "") { while (++x <= l) b += x < (l-p) ? "." : "*"; return b; }, p = 0; p < l; ++p) kprint(f(p, l));
function dum( maxStars ) {
if( maxStars ) {
for( local mainRun = 0; mainRun <= maxStars-1; mainRun++ ) {
local string = "";
for( local j = 1; j <= maxStars; j++ ) {
if( maxStars - j > mainRun ) {
string += ".";
}
else {
string += "*";
}
}
kprint( string );
}
}
}
local totalflake = 0;
local totaldoom = 0;
local totalslc = 0;
local iterations = 500;
for (local i = 1; i <= iterations; ++i)
{
local t, to;
print("Iteration " + i);
print("---");
print("Flake's method: ");
t = SqTimer();
PrintRowz(12);
to = t.Elapsed.Microseconds.tointeger();
print("Took " + to + " us");
totalflake += to;
print("Total counter for Flake: " + totalflake);
print("");
print("Doom's method: ");
t = SqTimer();
dum(12);
to = t.Elapsed.Microseconds.tointeger();
print("Took " + to + " us");
totaldoom += to;
print("Total counter for Doom: " + totaldoom);
print("");
print("SLC's method: ");
t = SqTimer();
Generate(12);
to = t.Elapsed.Microseconds.tointeger();
print("Took " + to + " us");
totalslc += to;
print("Total counter for SLC: " + totalslc);
print("");
print("---");
print("Iteration complete");
print("");
}
print("Total iterations: " + iterations);
print("Average for Flake: " + totalflake / iterations + " us");
print("Average for Doom: " + totaldoom / iterations + " us");
print("Average for SLC: " + totalslc / iterations + " us");