Profiling in SCL

You can profile performance (speed) of SCL routines using the following profiling features.

  1. _profile.framerate can be used to display the average framerate: log(_profiler.framerate)
  2. profile routine command in routines. After running, use _profiler.time to get length of time all executions ran for.
  3. create profile object to time routines over many frames, or to get time it takes to process all operations of a frame
  4. create routine as Start profile routine r2 where repeat=100000 log(_profiler.time) end create routine as r2 var aa=8+3 end

    Use 'profile routine' to measure how long it takes a routine to execute for the indicated number of repeats. All executions will happen within a single frame and will block other operations until it is complete. For profiling between frames create a 'profile' object.

    create profiler as F1 where routine=F1Routine // times the average time to run the routine over 500 frames frames=500 completion=(sub create routine log("F1 time: "+F1.time) end) end create profiler as All1 where // without a routine specified, average time to complete frame operations over 500 frames frames=500 completion=(sub create routine log("All time:"+All1.time) end) end create routine as Start Test1() launch Null insert into Null where alt=(sub // every 10 ms, re-draw junk (just to waste some time for testing purposes) create wait where delay=10 repeat=forever completion=(sub create routine as F1Routine draw onto Null clear strokestyle "red" strokerect 100,100,100,100 stroke enddraw end) end) insert into Null where alt=(sub // launch profilers a second after start-up create wait where delay=1000 completion=(sub create routine log("profiling starts") launch All1 launch F1 log("framerate is "+_profiler.framerate) log("wait about 10 seconds...") end) end) end create routine as Test1 // make 100 sprites so that something actually happens run routine MakeClone where repeat=100 end create sprite as Null end create routine as MakeClone clone from Null using original update sprite _clone where x=random(0,300) and y=random(0,300) draw onto _clone fillstyle "black" strokestyle "red" fillrect 10,10,10,10 strokerect 10,10,10,10 fill stroke enddraw insert into _clone where alt=(sub create rotation where speed=360 end) end