Guest User

Untitled

a guest
Nov 29th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package tests
  2. {
  3.     import de.polygonal.ds.DLL;
  4.     import de.polygonal.ds.DLLIterator;
  5.     import de.polygonal.ds.DLLNode;
  6.  
  7.     import flash.utils.getTimer;
  8.  
  9.     import nape.phys.Body;
  10.     import nape.phys.BodyIterator;
  11.  
  12.     import nape.phys.BodyList;
  13.  
  14.     import zpp_nape.util.ZNPNode_ZPP_Body;
  15.  
  16.     /**
  17.      */
  18.     public class Lists_Test extends Test
  19.     {
  20.         private var _dsList:DLL;
  21.         private var _napeList:BodyList;
  22.  
  23.         //
  24.         private var _isNape:Boolean = false;
  25.  
  26.         /**
  27.          */
  28.         public function Lists_Test()
  29.         {
  30.             super("", 10000000);
  31.  
  32.             if (_isNape) _napeList = napeListWriteTest(false, false);
  33.             else _dsList = dsListWriteTest(false, false);
  34.         }
  35.  
  36.         override public function run():void
  37.         {
  38.             if (_isNape)
  39.             {
  40. //              napeListWriteTest();        // 300 ms  (1 000 000)
  41. //              napeListReadDirectTest();  //  70 ms   (10 000 000)
  42. //              napeListReadIteratorTest(); // 1030 ms (10 000 000)
  43. //              napeListReadAtTest();      //  1677 ms (10 000 000)
  44.  
  45. //              napeListReadForeachTest();  // 1800 ms - anonymous function; 1360 ms - private method;  (10 000 000)
  46.             }
  47.             else
  48.             {
  49. //              dsListWriteTest();        // 300 ms  (1 000 000)
  50. //              dsListReadDirectTest();   // 70 ms   (10 000 000)
  51. //              dsListReadIteratorTest(); // 400 ms  (10 000 000)
  52. //              dsListReadAtTest();       // 1750 ms (10 000 000)
  53.             }
  54.         }
  55.  
  56.         private function dsListReadAtTest():void
  57.         {
  58.             var bodyObj:Body;
  59.  
  60.             var time:int = getTimer();
  61.  
  62.             var len:int = _dsList.size();
  63.             for (var i:int = 0; i < len; i++)
  64.             {
  65.                 bodyObj = _dsList.getNodeAt(i).val as Body;
  66.             }
  67.  
  68.             time = getTimer() - time;
  69.             timeResult = time;
  70.         }
  71.  
  72.         /**
  73.          * Nape read 'at' test
  74.          */
  75.         private function napeListReadAtTest():void
  76.         {
  77.             var bodyObj:Body;
  78.  
  79.             var time:int = getTimer();
  80.  
  81.             var len:int = _napeList.length;
  82.             for (var i:int = 0; i < len; i++)
  83.             {
  84.                 bodyObj = _napeList.at(i);
  85.             }
  86.  
  87.             time = getTimer() - time;
  88.             timeResult = time;
  89.         }
  90.  
  91.         /**
  92.          * DS read 'direct' test
  93.          */
  94.         private function dsListReadDirectTest(isNeedResults:Boolean = true):void
  95.         {
  96.             var bodyObj:Object;
  97.             var node:DLLNode;
  98.             var dll:DLL = _dsList;
  99.  
  100.             var time:int = getTimer();
  101.  
  102.             node = dll.head;
  103.  
  104.             while(node)
  105.             {
  106.                 bodyObj = node.val;
  107.                 node = node.next;
  108.             }
  109.  
  110.             time = getTimer() - time;
  111.             if (isNeedResults) timeResult = time;
  112.         }
  113.  
  114.         /**
  115.          * Nape read 'direct' test
  116.          */
  117.         private function napeListReadDirectTest(isNeedResults:Boolean = true):void
  118.         {
  119.             var bodyObj:Body;
  120.             var bodyList:BodyList = _napeList;
  121.             var node:ZNPNode_ZPP_Body;
  122.  
  123.             var time:int = getTimer();
  124.  
  125.             node = bodyList.zpp_inner.inner.head;
  126.  
  127.             while(node)
  128.             {
  129.                 bodyObj = node.elt.outer;
  130.                 node = node.next;
  131.             }
  132.  
  133.             time = getTimer() - time;
  134.             if (isNeedResults) timeResult = time;
  135.         }
  136.  
  137.         /**
  138.          * Nape read 'foreach' test
  139.          */
  140.         private function napeListReadForeachTest(isNeedResults:Boolean = true):void
  141.         {
  142.             var bodyObj:Body;
  143.  
  144.             var time:int = getTimer();
  145.  
  146.             _napeList.foreach(function(body:Body):void
  147.             {
  148.                 bodyObj = body;
  149.             });
  150.  
  151. //          _napeList.foreach(forEachBody);
  152.  
  153.             time = getTimer() - time;
  154.             if (isNeedResults) timeResult = time;
  155.         }
  156.  
  157.         private function forEachBody(body:Body):void
  158.         {
  159.             body;
  160.         }
  161.  
  162.         /**
  163.          * DS read 'iterator' test
  164.          */
  165.         private function dsListReadIteratorTest(isNeedResults:Boolean = true):void
  166.         {
  167.             var bodyObj:Body;
  168.             var iterator:DLLIterator = _dsList.iterator() as DLLIterator;
  169.  
  170.             var time:int = getTimer();
  171.  
  172.             while(iterator.hasNext())
  173.             {
  174.                 bodyObj = iterator.next() as Body;
  175.             }
  176.  
  177.             time = getTimer() - time;
  178.             if (isNeedResults) timeResult = time;
  179.         }
  180.  
  181.         /**
  182.          * Nape read 'iterator' test
  183.          */
  184.         private function napeListReadIteratorTest(isNeedResults:Boolean = true):void
  185.         {
  186.             var bodyObj:Body;
  187.             var iterator:BodyIterator = _napeList.iterator();
  188.  
  189.             var time:int = getTimer();
  190.  
  191.             while(iterator.hasNext())
  192.             {
  193.                 bodyObj = iterator.next();
  194.             }
  195.  
  196.             time = getTimer() - time;
  197.             if (isNeedResults) timeResult = time;
  198.         }
  199.  
  200.         /**
  201.          * DS write test
  202.          */
  203.         private function dsListWriteTest(isNeedResults:Boolean = true, writeUnique:Boolean = false):DLL
  204.         {
  205.             var bodyObj:Body = new Body();
  206.             var dll:DLL = new DLL();
  207.  
  208.             var i:int;
  209.             var time:int;
  210.  
  211.             if (writeUnique)
  212.             {
  213.                 time = getTimer();
  214.                 for (i = 0; i < iterations; i++)
  215.                 {
  216.                     dll.append(new Body());
  217.                 }
  218.                 time = getTimer() - time;
  219.             }
  220.             else
  221.             {
  222.                 time = getTimer();
  223.                 for (i = 0; i < iterations; i++)
  224.                 {
  225.                     dll.append(bodyObj);
  226.                 }
  227.                 time = getTimer() - time;
  228.             }
  229.  
  230.             if (isNeedResults) timeResult = time;
  231.  
  232.             return dll;
  233.         }
  234.  
  235.         /**
  236.          * Nape write test
  237.          */
  238.         private function napeListWriteTest(isNeedResults:Boolean = true, writeUnique:Boolean = false):BodyList
  239.         {
  240.             var bodyObj:Body = new Body();
  241.             var bodyList:BodyList = new BodyList();
  242.  
  243.             var i:int;
  244.             var time:int;
  245.  
  246.             if (writeUnique)
  247.             {
  248.                 time = getTimer();
  249.                 for (i = 0; i < iterations; i++)
  250.                 {
  251.                     bodyList.add(new Body());
  252.                 }
  253.                 time = getTimer() - time;
  254.             }
  255.             else
  256.             {
  257.                 time = getTimer();
  258.                 for (i = 0; i < iterations; i++)
  259.                 {
  260.                     bodyList.add(bodyObj);
  261.                 }
  262.                 time = getTimer() - time;
  263.             }
  264.  
  265.             if (isNeedResults) timeResult = time;
  266.  
  267.             return bodyList;
  268.         }
  269.     }
  270. }
Add Comment
Please, Sign In to add comment