priorityQueueTest.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. var PriorityQueue = require('../lib/priorityQueue');
  2. //var Queue = require('./PriorityQueue');
  3. //
  4. //var queue = new Queue();
  5. function testPriorityQueue(num, count){
  6. var queue = PriorityQueue.createPriorityQueue();
  7. for(var k = 0; k < num; k++){
  8. var testCase = [];
  9. var result = new Array(count);
  10. for(var i = 0; i < count; i++){
  11. testCase[i] = Math.random()*count;
  12. }
  13. var start = (new Date()).getTime();
  14. for(var i = 0; i < count; i++)
  15. queue.offer(testCase[i]);
  16. var end = (new Date()).getTime();
  17. console.log(end - start);
  18. start = (new Date()).getTime();
  19. // var value = queue.pop();
  20. for(var i = 0; i < count; i++){
  21. result[i] = queue.pop();
  22. // next = result[i];
  23. // if(value > next){
  24. // console.log('PriorityQueue error!');
  25. // console.log(queue);
  26. // console.log(result);
  27. // break;
  28. // }
  29. // value = next;
  30. // queue.pop();
  31. }
  32. end = (new Date()).getTime();
  33. console.log(end - start);
  34. // console.log(result);
  35. var start = result[0];
  36. for(var i = 1; i < count; i++){
  37. var next = result[i];
  38. if(start > next){
  39. console.log("Error!!!!!!");
  40. console.log("start : " + start + " next : " + next + " i : " + i);
  41. // console.log(result);
  42. break;
  43. }
  44. start = next;
  45. }
  46. console.log('After the ' + k + ' iteration with test count : ' + count);
  47. }
  48. }
  49. testPriorityQueue(10, 100000);
  50. //var test = [];
  51. //start = Date.now();
  52. //var k;
  53. //for(var i = 0; i < 100000000; i++){
  54. // k = i + 34354/i ;
  55. //}
  56. //end = Date.now();
  57. //
  58. //console.log(end - start);