Advertisement
truefire

TypedDictionary vs Hash

Mar 21st, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Comparing TypedDictionary to Hash
  2.  *
  3.  * Can easily be switched platform-specifically as interface is identical
  4.  * I tried the tests with Top having 1 subclass, and Top having 8 subclasses, same results
  5.  */
  6.  
  7. //SAMPLE DATA:
  8.  
  9. Debug.hx:21: Dict Set String : 1194
  10. Debug.hx:21: Dict Set Class : 519
  11. Debug.hx:21: Hash Set : 3614
  12. Debug.hx:21: Dict Get String : 778
  13. Debug.hx:21: Dict Get Class : 390
  14. Debug.hx:21: Hash Get : 3334
  15.  
  16. Debug.hx:21: Dict Set String : 1223
  17. Debug.hx:21: Dict Set Class : 515
  18. Debug.hx:21: Hash Set : 3639
  19. Debug.hx:21: Dict Get String : 816
  20. Debug.hx:21: Dict Get Class : 395
  21. Debug.hx:21: Hash Get : 3540
  22.  
  23. Debug.hx:21: Dict Set String : 1184
  24. Debug.hx:21: Dict Set Class : 557
  25. Debug.hx:21: Hash Set : 3894
  26. Debug.hx:21: Dict Get String : 802
  27. Debug.hx:21: Dict Get Class : 397
  28. Debug.hx:21: Hash Get : 3526
  29.  
  30. //THE TEST
  31.  
  32. package ;
  33.  
  34. import flash.Lib;
  35. import flash.utils.TypedDictionary;
  36. import libTF.utils.Debug;
  37.  
  38. class Main
  39. {
  40.    
  41.     static function main()
  42.     {
  43.         //traces
  44.         FlashConnect.redirect();
  45.        
  46.         //create dicts
  47.         var c0:TypedDictionary < String, Top > = new TypedDictionary < String, Top > ();
  48.         var c1:TypedDictionary < Class<Top>, Top > = new TypedDictionary < Class<Top>, Top > ();
  49.         var c2:Hash<Top> = new Hash<Top>();
  50.        
  51.         //vars for use in loop
  52.         var i:Int;
  53.         var b:Top = new B();
  54.        
  55.         //run tests
  56.         i = 0;
  57.         Debug.startBench();
  58.         while (i < 10000000)
  59.         {
  60.             c0.set("B", b);
  61.             i++;
  62.         }
  63.         Debug.getBench("Dict Set String");
  64.        
  65.         i = 0;
  66.         Debug.startBench();
  67.         while (i < 10000000)
  68.         {
  69.             c1.set(B, b);
  70.             i++;
  71.         }
  72.         Debug.getBench("Dict Set Class");
  73.        
  74.         i = 0;
  75.         Debug.startBench();
  76.         while (i < 10000000)
  77.         {
  78.             c2.set("B", b);
  79.             i++;
  80.         }
  81.         Debug.getBench("Hash Set");
  82.        
  83.        
  84.         i = 0;
  85.         Debug.startBench();
  86.         while (i < 10000000)
  87.         {
  88.             c0.get("B");
  89.             i++;
  90.         }
  91.         Debug.getBench("Dict Get String");
  92.        
  93.         i = 0;
  94.         Debug.startBench();
  95.         while (i < 10000000)
  96.         {
  97.             c1.get(B);
  98.             i++;
  99.         }
  100.         Debug.getBench("Dict Get Class");
  101.        
  102.         i = 0;
  103.         Debug.startBench();
  104.         while (i < 10000000)
  105.         {
  106.             c2.get("B");
  107.             i++;
  108.         }
  109.         Debug.getBench("Hash Get");
  110.     }
  111.    
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement