mramine364

sort Test

May 14th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.09 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Quick Sort</title>
  5. </head>
  6. <body>
  7. <script type="text/javascript" src="quick.js"></script>
  8. <script type="text/javascript" src="merge.js"></script>
  9. <script>
  10.  
  11. var m = randTxT(500,5000,-1000,1000);
  12. VS(m);
  13. function VS(M){
  14.     var t;
  15.     t = Date.now();
  16.     for(var i=0;i<M.length;i++){
  17.         quickSort(M[i].slice());
  18.     }console.log("quickSort time (ms): "+(Date.now()-t));
  19.  
  20.     t = Date.now();
  21.     for(var i=0;i<M.length;i++){
  22.         M[i].slice().sort(compare);
  23.     }console.log("javaScriptSort time (ms): "+(Date.now()-t));
  24.  
  25.     t = Date.now();
  26.     for(var i=0;i<M.length;i++){
  27.         mergeSort(M[i].slice());
  28.     }console.log("mergeSort time (ms): "+(Date.now()-t));
  29.     console.log();
  30.  
  31. }
  32.  
  33. function compare(a, b) {
  34.     if( a<b )
  35.         return -1;
  36.     if( a==b )
  37.         return 0;
  38.     return 1;
  39. }
  40.  
  41. function randT(n,min,max){
  42.     var res = [], i=0;
  43.     while( i<n ){
  44.         res.push( Math.floor(Math.random()*(max-min+1)+min) );
  45.         i++;
  46.     }
  47.     return res;
  48. }
  49. function randTxT(n,m,min,max){
  50.     var res = [], i=0;
  51.     while( i<n ){
  52.         res.push( randT(m,min,max) );
  53.         i++;
  54.     }
  55.     return res;
  56. }
  57. </script>
  58. </body>
  59. </html>
Advertisement
Add Comment
Please, Sign In to add comment