<commit_before>/* performance benchmark */
/* This script expects node.js */

'use strict';

var FastPriorityQueue = require('../FastPriorityQueue.js');
var PriorityQueue = require('js-priority-queue');
var Heap = require('heap');
var Benchmark = require('benchmark');
var os = require('os');
var binaryheapx = require('binaryheapx').Constructor;
var pq = require('priority_queue');
var jsHeap = require('js-heap');
var qp = require('queue-priority');
var priorityqueuejs = require('priorityqueuejs');
var qheap = require('qheap');
var BinaryHeap = require('yabh');

// very fast semi-random function
function rand(i) {
  i = i + 10000;
  i = i ^ (i << 16);
  i = (i >> 5) ^ i ;
  return i & 0xFF;
}
var defaultcomparator = function(a, b) {
  return a < b;
};

function basictest() {
  var b1 = new FastPriorityQueue(defaultcomparator);
  var b2 = new Heap(function(a, b) {
    return a - b;
  });
  for (var i = 0 ; i < 2000  ; i++) {
    b1.add(rand(i));
    b2.push(rand(i));
  }
  for (i = 128 ; i < 128 * 10  ; i++) {
    b1.add(rand(i));
    b2.push(rand(i));
    var x1 = b1.poll();
    var x2 = b2.pop();
    if (x1 != x2) throw 'bug ' + x1 + ' ' + x2;
  }

}

function QueueEnqueueBench() {
  console.log('starting dynamic queue/enqueue benchmark');
  var suite = new Benchmark.Suite();
  // add tests
  var b = new BinaryHeap();
  for (var i = 0 ; i < 128  ; i++) {
    b.push(rand(i));
  }
  for (i = 128 ; i < 128 * 10  ; i++) {
    b.push(rand(i));
    b.pop();
  }

  var ms = suite
    .add('FastPriorityQueue', function() {
      var b = new FastPriorityQueue(defaultcomparator);
      for (var i = 0 ; i < 128  ; i++) {
        b.add(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.add(rand(i));
        b.poll();
      }
      return b;
    })
   .add('js-priority-queue', function() {
      var b = new PriorityQueue({comparator: function(a, b) {
        return b - a;
      }
                                });
      for (var i = 0 ; i < 128  ; i++) {
        b.queue(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.queue(rand(i));
        b.dequeue();
      }
      return b;
    })
    .add('heap.js', function() {
      var b = new Heap(function(a, b) {
        return a - b;
      });
      for (var i = 0 ; i < 128  ; i++) {
        b.push(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.push(rand(i));
        b.pop();
      }
      return b;
    })
    .add('binaryheapx', function() {
      var b = new binaryheapx();
      for (var i = 0 ; i < 128  ; i++) {
        b.add(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.add(rand(i));
        b.pop();
      }
      return b;
    })
    .add('priority_queue', function() {
      var b = new pq.PriorityQueue();
      for (var i = 0 ; i < 128  ; i++) {
        b.push(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.push(rand(i));
        b.shift();
      }
      return b;
    })
    .add('js-heap', function() {
      var b = new jsHeap();
      for (var i = 0 ; i < 128  ; i++) {
        b.push(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.push(rand(i));
        b.pop();
      }
      return b;
    })
    .add('queue-priority', function() {
      var b = new qp();
      for (var i = 0 ; i < 128  ; i++) {
        b.push(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.push(rand(i));
        b.pop();
      }
      return b;
    })
    .add('priorityqueuejs', function() {
      var b = new priorityqueuejs();
      for (var i = 0 ; i < 128  ; i++) {
        b.enq(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.enq(rand(i));
        b.deq();
      }
      return b;
    })
    .add('qheap', function() {
      var b = new qheap();
      for (var i = 0 ; i < 128  ; i++) {
        b.insert(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.insert(rand(i));
        b.remove();
      }
      return b;
    })
    .add('yabh', function() {
      var b = new BinaryHeap();
      for (var i = 0 ; i < 128  ; i++) {
        b.push(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.push(rand(i));
        b.pop();
      }
      return b;
    })
    // add listeners
    .on('cycle', function(event) {
      console.log(String(event.target));
    })
    .on('complete', function() {
      console.log('Fastest is ' + this.filter('fastest').map('name'));
    })
    // run async
    .run({'async': false});
}

var main = function() {
  basictest();
  console.log('Platform: ' + process.platform + ' ' + os.release() + ' ' + process.arch);
  console.log(os.cpus()[0]['model']);
  console.log('Node version ' + process.versions.node + ', v8 version ' + process.versions.v8);
  console.log();
  console.log('Comparing against: ');
  console.log('js-priority-queue: https://github.com/adamhooper/js-priority-queue', require("js-priority-queue/package.json").version);
  console.log('heap.js: https://github.com/qiao/heap.js', require("heap/package.json").version);
  console.log('binaryheapx: https://github.com/xudafeng/BinaryHeap', require("binaryheapx/package.json").version);
  console.log('priority_queue: https://github.com/agnat/js_priority_queue', require("priority_queue/package.json").version);
  console.log('js-heap: https://github.com/thauburger/js-heap', require("js-heap/package.json").version);
  console.log('queue-priority: https://github.com/augustohp/Priority-Queue-NodeJS', require("queue-priority/package.json").version);<commit_msg>Removing fastest output as it is creating trouble.<commit_after>/* performance benchmark */
/* This script expects node.js */

'use strict';

var FastPriorityQueue = require('../FastPriorityQueue.js');
var PriorityQueue = require('js-priority-queue');
var Heap = require('heap');
var Benchmark = require('benchmark');
var os = require('os');
var binaryheapx = require('binaryheapx').Constructor;
var pq = require('priority_queue');
var jsHeap = require('js-heap');
var qp = require('queue-priority');
var priorityqueuejs = require('priorityqueuejs');
var qheap = require('qheap');
var BinaryHeap = require('yabh');

// very fast semi-random function
function rand(i) {
  i = i + 10000;
  i = i ^ (i << 16);
  i = (i >> 5) ^ i ;
  return i & 0xFF;
}
var defaultcomparator = function(a, b) {
  return a < b;
};

function basictest() {
  var b1 = new FastPriorityQueue(defaultcomparator);
  var b2 = new Heap(function(a, b) {
    return a - b;
  });
  for (var i = 0 ; i < 2000  ; i++) {
    b1.add(rand(i));
    b2.push(rand(i));
  }
  for (i = 128 ; i < 128 * 10  ; i++) {
    b1.add(rand(i));
    b2.push(rand(i));
    var x1 = b1.poll();
    var x2 = b2.pop();
    if (x1 != x2) throw 'bug ' + x1 + ' ' + x2;
  }

}

function QueueEnqueueBench() {
  console.log('starting dynamic queue/enqueue benchmark');
  var suite = new Benchmark.Suite();
  // add tests
  var b = new BinaryHeap();
  for (var i = 0 ; i < 128  ; i++) {
    b.push(rand(i));
  }
  for (i = 128 ; i < 128 * 10  ; i++) {
    b.push(rand(i));
    b.pop();
  }

  var ms = suite
    .add('FastPriorityQueue', function() {
      var b = new FastPriorityQueue(defaultcomparator);
      for (var i = 0 ; i < 128  ; i++) {
        b.add(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.add(rand(i));
        b.poll();
      }
      return b;
    })
   .add('js-priority-queue', function() {
      var b = new PriorityQueue({comparator: function(a, b) {
        return b - a;
      }
                                });
      for (var i = 0 ; i < 128  ; i++) {
        b.queue(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.queue(rand(i));
        b.dequeue();
      }
      return b;
    })
    .add('heap.js', function() {
      var b = new Heap(function(a, b) {
        return a - b;
      });
      for (var i = 0 ; i < 128  ; i++) {
        b.push(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.push(rand(i));
        b.pop();
      }
      return b;
    })
    .add('binaryheapx', function() {
      var b = new binaryheapx();
      for (var i = 0 ; i < 128  ; i++) {
        b.add(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.add(rand(i));
        b.pop();
      }
      return b;
    })
    .add('priority_queue', function() {
      var b = new pq.PriorityQueue();
      for (var i = 0 ; i < 128  ; i++) {
        b.push(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.push(rand(i));
        b.shift();
      }
      return b;
    })
    .add('js-heap', function() {
      var b = new jsHeap();
      for (var i = 0 ; i < 128  ; i++) {
        b.push(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.push(rand(i));
        b.pop();
      }
      return b;
    })
    .add('queue-priority', function() {
      var b = new qp();
      for (var i = 0 ; i < 128  ; i++) {
        b.push(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.push(rand(i));
        b.pop();
      }
      return b;
    })
    .add('priorityqueuejs', function() {
      var b = new priorityqueuejs();
      for (var i = 0 ; i < 128  ; i++) {
        b.enq(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.enq(rand(i));
        b.deq();
      }
      return b;
    })
    .add('qheap', function() {
      var b = new qheap();
      for (var i = 0 ; i < 128  ; i++) {
        b.insert(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.insert(rand(i));
        b.remove();
      }
      return b;
    })
    .add('yabh', function() {
      var b = new BinaryHeap();
      for (var i = 0 ; i < 128  ; i++) {
        b.push(rand(i));
      }
      for (i = 128 ; i < 128 * 10  ; i++) {
        b.push(rand(i));
        b.pop();
      }
      return b;
    })
    // add listeners
    .on('cycle', function(event) {
      console.log(String(event.target));
    })
    // run async
    .run({'async': false});
}

var main = function() {
  basictest();
  console.log('Platform: ' + process.platform + ' ' + os.release() + ' ' + process.arch);
  console.log(os.cpus()[0]['model']);
  console.log('Node version ' + process.versions.node + ', v8 version ' + process.versions.v8);
  console.log();
  console.log('Comparing against: ');
  console.log('js-priority-queue: https://github.com/adamhooper/js-priority-queue', require("js-priority-queue/package.json").version);
  console.log('heap.js: https://github.com/qiao/heap.js', require("heap/package.json").version);
  console.log('binaryheapx: https://github.com/xudafeng/BinaryHeap', require("binaryheapx/package.json").version);
  console.log('priority_queue: https://github.com/agnat/js_priority_queue', require("priority_queue/package.json").version);
  console.log('js-heap: https://github.com/thauburger/js-heap', require("js-heap/package.json").version);
  console.log('queue-priority: https://github.com/augustohp/Priority-Queue-NodeJS', require("queue-priority/package.json").version);
{'fraction_non_alphanumeric': 0.19406764333514198, 'fraction_numerical': 0.030927835051546393, 'mean_word_length': 2.0365183964854476, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 7, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3170406', 'n_tokens_mistral': 4266, 'n_tokens_neox': 3949, 'n_words': 925}