Advertisement
snake5

SGScript - profiler injection system prototype

Apr 20th, 2013
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function test(){ print( "whoa" ); }
  2.  
  3. global totaltime = {};
  4. function inject( src, name )
  5. {
  6.     totaltime[ name ] = 0;
  7.     counter = function()
  8.     {
  9.         begin = ftime();
  10.         this[0]();
  11.         end = ftime();
  12.         totaltime[ this[1] ] += end - begin;
  13.     };
  14.     return closure( counter, [src,name] );
  15. }
  16.  
  17. test();
  18. test = inject( test, "test" );
  19.  
  20. begin = ftime();
  21. for( i = 0; i < 1000; ++i )
  22.     test();
  23. end = ftime();
  24.  
  25. printvar( totaltime );
  26. println( totaltime["test"] $ " out of " $ end-begin $ " seconds spent in 'test'" );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement