-
-
Save drakeirving/a99d768beca4c69d7c44050620777b2f to your computer and use it in GitHub Desktop.
Array Time Test v3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#TouhouDanmakufu[Single] | |
#ScriptVersion[3] | |
#Title["Array Time Test v3"] | |
@Initialize{ | |
TDebug(); | |
TMain(); | |
} | |
@MainLoop{ yield; } | |
@Event{ | |
if(GetEventType() == EV_REQUEST_LIFE){ SetScriptResult(10); } | |
} | |
let TEST_NORMAL = 0; | |
let TEST_CONTROL = 1; | |
let TEST_CONTROL_RAW = 2; | |
task TMain(){ | |
loop(60){yield;} | |
//array_test_fixed_rand(0, TEST_CONTROL, 5, 16, 5000000); | |
//array_test_fixed_rand(1, TEST_NORMAL, 5, 16, 5000000); | |
//array_test_fixed_rand(2, TEST_CONTROL, 5, 16, 10000000); | |
//array_test_fixed_rand(3, TEST_NORMAL, 5, 16, 10000000); | |
//array_test_fixed_rand(4, TEST_CONTROL, 5, 16, 15000000); | |
//array_test_fixed_rand(5, TEST_NORMAL, 5, 16, 15000000); | |
//array_test_fixed_rand(6, TEST_CONTROL, 5, 16, 20000000); | |
//array_test_fixed_rand(7, TEST_NORMAL, 5, 16, 20000000); | |
//array_test_fixed_rand(8, TEST_CONTROL, 5, 16, 25000000); | |
//array_test_fixed_rand(9, TEST_NORMAL, 5, 16, 25000000); | |
} | |
/* | |
# NOTES | |
- FPS is a bad measure because it stays at 60 until it slows down and is not necessarily linear past that | |
- Meanwhile, for a given number of iterations, putting in more iterations per frame asymptotically speeds up process | |
- Hence no yielding at all during a test is optimal | |
- AddScore() has less overhead than incrementing a variable or something | |
*/ | |
// array test: access element at specific index in fixed-size array | |
function array_test_fixed_one(test_line, test_type, test_count, size_pow2, iters){ | |
let list = [1]; | |
loop(size_pow2){ | |
list = list ~ list; | |
} | |
let size = length(list); | |
loop(60){yield;} | |
let results = []; | |
ascent(i in 0..test_count){ | |
results = results ~ ["..."]; | |
SetDebugText(results, test_line); | |
update(); | |
let j = floor(length(list)/test_count*i); | |
let start = GetStageTime(); | |
alternative(test_type) | |
case(TEST_NORMAL){ | |
loop(iters){ | |
AddScore(list[j]); | |
} | |
} | |
case(TEST_CONTROL){ | |
loop(iters){ | |
AddScore(1); | |
} | |
} | |
let end = GetStageTime(); | |
let time = end - start; | |
results[length(results)-1] = itoa(time); | |
update(); | |
} | |
SetDebugText(results, test_line); | |
return unstringify(results); | |
} | |
// array test: access all elements looping through fixed-size array | |
function array_test_fixed_all(test_line, test_type, test_count, size_pow2, iters){ | |
let list = [1]; | |
loop(size_pow2){ | |
list = list ~ list; | |
} | |
let size = length(list); | |
loop(60){yield;} | |
let results = []; | |
ascent(i in 0..test_count){ | |
results = results ~ ["..."]; | |
SetDebugText(results, test_line); | |
update(); | |
let start = GetStageTime(); | |
let j = 0; | |
alternative(test_type) | |
case(TEST_NORMAL){ | |
loop(floor(iters/size)){ | |
loop(size){ | |
AddScore(list[j]); | |
j++; | |
} | |
j %= size; | |
} | |
} | |
case(TEST_CONTROL){ | |
loop(floor(iters/size)){ | |
loop(size){ | |
AddScore(1); | |
j++; | |
} | |
j %= size; | |
} | |
} | |
let end = GetStageTime(); | |
let time = end - start; | |
results[length(results)-1] = itoa(time); | |
update(); | |
} | |
SetDebugText(results, test_line); | |
return unstringify(results); | |
} | |
// array test: access random elements in fixed-size array | |
function array_test_fixed_rand(test_line, test_type, test_count, size_pow2, iters){ | |
let list = [1]; | |
loop(size_pow2){ | |
list = list ~ list; | |
} | |
let size = length(list); | |
loop(60){yield;} | |
let results = []; | |
ascent(i in 0..test_count){ | |
results = results ~ ["..."]; | |
SetDebugText(results, test_line); | |
update(); | |
let start = GetStageTime(); | |
alternative(test_type) | |
case(TEST_NORMAL){ | |
loop(iters){ | |
AddScore(list[ floor(rand(0, size)) ]); | |
} | |
} | |
case(TEST_CONTROL){ | |
loop(iters){ | |
floor(rand(0, size)); | |
AddScore(1); | |
} | |
} | |
let end = GetStageTime(); | |
let time = end - start; | |
results[length(results)-1] = itoa(time); | |
update(); | |
} | |
SetDebugText(results, test_line); | |
return unstringify(results); | |
} | |
// object value test: access element at specific index in fixed-size objval table mimicking array | |
function objval_test_fixed_one(test_line, test_type, test_count, size_pow2, iters){ | |
let list = ObjShot_Create(OBJ_SHOT); | |
ascent(i in 0..2^size_pow2){ | |
Obj_SetValue(list, itoa(i), 1); | |
Obj_SetValue(list, "_length", Obj_GetValueD(list, "_length", 0) + 1); | |
} | |
let size = Obj_GetValueD(list, "_length", 0); | |
loop(60){yield;} | |
let results = []; | |
ascent(i in 0..test_count){ | |
results = results ~ ["..."]; | |
SetDebugText(results, test_line); | |
update(); | |
let j = floor(length(list)/test_count*i); | |
let start = GetStageTime(); | |
alternative(test_type) | |
case(TEST_NORMAL){ | |
loop(iters){ | |
AddScore(Obj_GetValue(list, itoa(j))); | |
} | |
} | |
case(TEST_CONTROL){ | |
loop(iters){ | |
itoa(j); | |
AddScore(1); | |
} | |
} | |
let end = GetStageTime(); | |
let time = end - start; | |
results[length(results)-1] = itoa(time); | |
update(); | |
} | |
SetDebugText(results, test_line); | |
return unstringify(results); | |
} | |
// object value test: access all elements looping through fixed-size objval table mimicking array | |
function objval_test_fixed_all(test_line, test_type, test_count, size_pow2, iters){ | |
let list = ObjShot_Create(OBJ_SHOT); | |
ascent(i in 0..2^size_pow2){ | |
Obj_SetValue(list, itoa(i), 1); | |
Obj_SetValue(list, "_length", Obj_GetValueD(list, "_length", 0) + 1); | |
} | |
let size = Obj_GetValueD(list, "_length", 0); | |
loop(60){yield;} | |
let results = []; | |
ascent(i in 0..test_count){ | |
results = results ~ ["..."]; | |
SetDebugText(results, test_line); | |
update(); | |
let start = GetStageTime(); | |
let j = 0; | |
alternative(test_type) | |
case(TEST_NORMAL){ | |
loop(floor(iters/size)){ | |
loop(size){ | |
AddScore(Obj_GetValue(list, itoa(j))); | |
j++; | |
} | |
j %= size; | |
} | |
} | |
case(TEST_CONTROL){ | |
loop(floor(iters/size)){ | |
loop(size){ | |
itoa(j); | |
AddScore(1); | |
j++; | |
} | |
j %= size; | |
} | |
} | |
case(TEST_CONTROL_RAW){ | |
loop(floor(iters/size)){ | |
loop(size){ | |
AddScore(1); | |
j++; | |
} | |
j %= size; | |
} | |
} | |
let end = GetStageTime(); | |
let time = end - start; | |
results[length(results)-1] = itoa(time); | |
update(); | |
} | |
SetDebugText(results, test_line); | |
return unstringify(results); | |
} | |
// object value test: access random elements in fixed-size objval table mimicking array | |
function objval_test_fixed_rand(test_line, test_type, test_count, size_pow2, iters){ | |
let list = ObjShot_Create(OBJ_SHOT); | |
ascent(i in 0..2^size_pow2){ | |
Obj_SetValue(list, itoa(i), 1); | |
Obj_SetValue(list, "_length", Obj_GetValueD(list, "_length", 0) + 1); | |
} | |
let size = Obj_GetValueD(list, "_length", 0); | |
loop(60){yield;} | |
let results = []; | |
ascent(i in 0..test_count){ | |
results = results ~ ["..."]; | |
SetDebugText(results, test_line); | |
update(); | |
let start = GetStageTime(); | |
alternative(test_type) | |
case(TEST_NORMAL){ | |
loop(iters){ | |
AddScore(Obj_GetValue(list, itoa( floor(rand(0, size)) ))); | |
} | |
} | |
case(TEST_CONTROL){ | |
loop(iters){ | |
itoa( floor(rand(0, size)) ); | |
AddScore(1); | |
} | |
} | |
case(TEST_CONTROL_RAW){ | |
loop(iters){ | |
floor(rand(0, size)); | |
AddScore(1); | |
} | |
} | |
let end = GetStageTime(); | |
let time = end - start; | |
results[length(results)-1] = itoa(time); | |
update(); | |
} | |
SetDebugText(results, test_line); | |
return unstringify(results); | |
} | |
// common data test: access random elements in fixed-size commondata table mimicking array | |
// note the t variable is necessary for the control, which inflates times compared to the common data area test | |
function commondata_test_fixed_rand(test_line, test_type, test_count, size_pow2, iters){ | |
let list = "arr0"; | |
ascent(i in 0..2^size_pow2){ | |
SetCommonData(list~itoa(i), 1); | |
SetCommonData(list~"_length", GetCommonData(list~"_length", 0) + 1); | |
} | |
let size = GetCommonData(list~"_length", 0); | |
loop(60){yield;} | |
let results = []; | |
ascent(i in 0..test_count){ | |
results = results ~ ["..."]; | |
SetDebugText(results, test_line); | |
update(); | |
let start = GetStageTime(); | |
let t; | |
alternative(test_type) | |
case(TEST_NORMAL){ | |
loop(iters){ | |
t = list~itoa( floor(rand(0, size)) ); | |
AddScore(GetCommonData(t, 0)); | |
} | |
} | |
case(TEST_CONTROL){ | |
loop(iters){ | |
t = list~itoa( floor(rand(0, size)) ); | |
AddScore(1); | |
} | |
} | |
case(TEST_CONTROL_RAW){ | |
loop(iters){ | |
t = floor(rand(0, size)); | |
AddScore(1); | |
} | |
} | |
let end = GetStageTime(); | |
let time = end - start; | |
results[length(results)-1] = itoa(time); | |
update(); | |
} | |
SetDebugText(results, test_line); | |
return unstringify(results); | |
} | |
// common data area test: access random elements in fixed-size commondata area table mimicking array | |
function commondataarea_test_fixed_rand(test_line, test_type, test_count, size_pow2, iters){ | |
let list = "arr0"; | |
CreateCommonDataArea(list); | |
ascent(i in 0..2^size_pow2){ | |
SetAreaCommonData(list, itoa(i), 1); | |
} | |
let size = length(GetCommonDataValueKeyList(list)); | |
loop(60){yield;} | |
let results = []; | |
ascent(i in 0..test_count){ | |
results = results ~ ["..."]; | |
SetDebugText(results, test_line); | |
update(); | |
let start = GetStageTime(); | |
alternative(test_type) | |
case(TEST_NORMAL){ | |
loop(iters){ | |
AddScore(GetAreaCommonData(list, itoa( floor(rand(0, size)) ), 0)); | |
} | |
} | |
case(TEST_CONTROL){ | |
loop(iters){ | |
itoa( floor(rand(0, size)) ); | |
AddScore(1); | |
} | |
} | |
case(TEST_CONTROL_RAW){ | |
loop(iters){ | |
floor(rand(0, size)); | |
AddScore(1); | |
} | |
} | |
let end = GetStageTime(); | |
let time = end - start; | |
results[length(results)-1] = itoa(time); | |
update(); | |
} | |
SetDebugText(results, test_line); | |
return unstringify(results); | |
} | |
//////////////// | |
// utils | |
//////////////// | |
function update(){ | |
yield; yield; | |
} | |
function unstringify(a){ | |
let a_s = ToString(a); | |
if(length(a_s) > 0){ | |
if(a_s[0] == '[' && a_s[length(a_s)-1] == ']'){ | |
if(length(a) == length(a_s)){ | |
// string of array | |
let b = SplitString(a[1..length(a)-1], ","); | |
ascent(i in 0..length(b)){ | |
b[i] = TrimString(b[i]); | |
} | |
return unstringify(b); | |
}else{ | |
// nonempty array | |
let b = []; | |
ascent(i in 0..length(a)){ | |
b = b ~ [unstringify(a[i])]; | |
} | |
return b; | |
} | |
}else if(length(a) == length(a_s)){ | |
let r = ator(a); | |
if(r != 0){ | |
// string of number | |
return r; | |
}else{ | |
let zc = 0; let pc = 0; | |
let b = TrimString(a); | |
ascent(i in 0..length(b)){ | |
if(b[i] == '0'){ zc++; } | |
else if(b[i] == '.' && pc == 0){ pc++; } | |
else{ | |
if(b == "true"){ return true; } | |
if(b == "false"){ return false; } | |
else{ | |
// generic string | |
return a; | |
} | |
} | |
} | |
// string of 0 | |
return 0; | |
} | |
} | |
} | |
// number or empty array | |
return a; | |
} | |
function SetDebugText(s, line){ | |
SetAreaCommonData("DEBUG_TEXT", rtos("00", line), ToString(s)); | |
SetAreaCommonData("DEBUG", "DEBUG_TEXT_CHANGED", true); | |
} | |
task TDebug(){ | |
CreateCommonDataArea("DEBUG"); | |
CreateCommonDataArea("DEBUG_TEXT"); | |
let debugobj = ObjText_Create(); | |
ObjText_SetText(debugobj, ""); | |
ObjText_SetFontSize(debugobj, 12); | |
ObjText_SetMaxWidth(debugobj, GetStgFrameWidth() - 4); | |
ObjRender_SetPosition(debugobj, 4, 28, 0); | |
let debugstr = ""; | |
loop{ | |
if(GetAreaCommonData("DEBUG", "DEBUG_TEXT_CHANGED", false)){ | |
SetAreaCommonData("DEBUG", "DEBUG_TEXT_CHANGED", false); | |
let lines = GetCommonDataValueKeyList("DEBUG_TEXT"); | |
debugstr = ""; | |
ascent(i in 0..length(lines)){ | |
debugstr = debugstr ~ GetAreaCommonData("DEBUG_TEXT", lines[i], "") ~ "[r]"; | |
} | |
ObjText_SetText(debugobj, debugstr); | |
} | |
yield; | |
} | |
Obj_Delete(debugobj); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment