Skip to content

Instantly share code, notes, and snippets.

@drakeirving
Created August 7, 2015 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drakeirving/e999d52c50cc7dc54e2c to your computer and use it in GitHub Desktop.
Save drakeirving/e999d52c50cc7dc54e2c to your computer and use it in GitHub Desktop.
Array Time Test
#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Array Time Test"]
@Initialize{
TDebug();
TMain();
}
@MainLoop{ yield; }
@Event{
if(GetEventType() == EV_REQUEST_LIFE){ SetScriptResult(10); }
}
task TMain(){
loop(60){yield;}
//test1(17);
//test1b(17);
//test2(14,19);
//test2b(14,19);
//test3(14,19);
}
// array test: access specific elements in constant-size array
function test1(num){
let list = [1];
loop(num){
list = list ~ list;
}
loop(60){yield;}
let time_total = 0;
let results = [];
ascent(i in 0..10){
let j = floor(length(list)/10*i);
loop(3){
loop(60){
loop(200000){
AddScore(list[j]);
}
yield;
}
time_total += GetCurrentFps();
}
results = results ~ [rtos("00.00", time_total / 3)];
SetDebugText(results, 0);
time_total = 0;
}
}
// control for test1()
function test1b(num){
let time_total = 0;
let results = [];
ascent(i in 0..10){
loop(3){
loop(60){
loop(200000){
AddScore(1);
}
yield;
}
time_total += GetCurrentFps();
}
results = results ~ [rtos("00.00", time_total / 3)];
SetDebugText(results, 0);
time_total = 0;
}
}
// array test: access every element in doubling-size array
function test2(num1, num2){
let list = [1];
loop(num1){
list = list ~ list;
}
loop(60){yield;}
let time_total = 0;
let results = [];
loop(num2 - num1){
ascent(j in 0..5){
loop(60){
ascent(i in 0..length(list)){
AddScore(list[i]);
}
yield;
}
time_total += GetCurrentFps();
}
results = results ~ [rtos("00.00", time_total / 5)];
SetDebugText(results, 0);
list = list ~ list;
time_total = 0;
}
}
// control for test2()
function test2b(num1, num2){
let count = 2^num1;
let time_total = 0;
let results = [];
loop(num2 - num1){
ascent(j in 0..5){
loop(60){
ascent(i in 0..count){
AddScore(1);
}
yield;
}
time_total += GetCurrentFps();
}
results = results ~ [rtos("00.00", time_total / 5)];
SetDebugText(results, 0);
count *= 2;
time_total = 0;
}
}
// array test: access specific element in doubling-size array
function test3(num1, num2){
let list = [1];
loop(num1){
list = list ~ list;
}
loop(60){yield;}
let time_total = 0;
let results = [];
loop(num2 - num1){
let j = floor(length(list)/2);
loop(3){
loop(60){
loop(200000){
AddScore(list[j]);
}
yield;
}
time_total += GetCurrentFps();
}
results = results ~ [rtos("00.00", time_total / 3)];
SetDebugText(results, 0);
list = list ~ list;
time_total = 0;
}
}
function SetDebugText(s, line){
SetAreaCommonData("DEBUG_TEXT", itoa(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);
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", itoa(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