Advertisement
snake5

SGScript - concept of an optimization

May 7th, 2013
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // CODE
  2. obj = { x = 5, y = 6 };
  3.  
  4. its = 1000000;
  5.  
  6. t = ftime();
  7. for( i = 0; i < its; ++i )
  8. {
  9.     a = obj.x;
  10.     a = obj.y;
  11. }
  12. println( "old method: " $ ftime() - t $ " seconds" );
  13.  
  14. t = ftime();
  15. for( i = 0; i < its; ++i )
  16. {
  17.     a = obj.0;
  18.     a = obj.1;
  19. }
  20. println( "new method: " $ ftime() - t $ " seconds" );
  21.  
  22.  
  23. // OUTPUT
  24. old method: 0.542 seconds
  25. new method: 0.384 seconds
  26.  
  27.  
  28. // NEW SYNTAX CONCEPT
  29. obj = { x = 5, y = 6 };
  30. assume obj = x, y; // validated by name, order of parameters here must match order of insertion (which is equal to the order of the internal array) in the object
  31. for( i = 0; i < its; ++i )
  32. {
  33.     a = obj.x; // translated to obj.0 in bytecode
  34.     a = obj.y; // translated to obj.1 in bytecode
  35. }
  36.  
  37.  
  38. // NEW SYNTAX CONCEPT v2
  39. obj = { x = 5, y = 6 };
  40. typedef myObject = x, y; // same as "assume" but only defines the structure, doesn't actually assume the properties of a variable name
  41. ...
  42. assume obj : myObject; // allows keeping the actual property list with the object, as well as avoiding the need to re-specify all of the parameters each time a function uses the object a lot
  43. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement