Skip to content

Commit

Permalink
Release v2.0.0-0
Browse files Browse the repository at this point in the history
  • Loading branch information
petkaantonov committed Dec 25, 2013
1 parent a6d7416 commit 73fcc1c
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 252 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,3 +5,4 @@ npm-debug.log
nodex64.exe
throwaway.js
reader.js
bump.js
1 change: 1 addition & 0 deletions .npmignore
Expand Up @@ -28,3 +28,4 @@ changelog.js
.travis.yml
sauce_connect.log
nodex64.exe
bump.js
18 changes: 17 additions & 1 deletion README.md
Expand Up @@ -5,7 +5,7 @@ Extremely fast [double-ended queue](http://en.wikipedia.org/wiki/Double-ended_qu
- [Stack](http://en.wikipedia.org/wiki/Stack_\(abstract_data_type\))
- [Queue](http://en.wikipedia.org/wiki/Queue_\(data_structure\))

The implementation is GC and CPU cache friendly [circular buffer](http://en.wikipedia.org/wiki/Circular_buffer). It will run circles around any "linked list" implementation.
The implementation is GC and CPU cache friendly [circular buffer](http://en.wikipedia.org/wiki/Circular_buffer). [It will run circles around any "linked list" implementation](#performance).

Every queue operation is done in constant `O(1)` - including random access from `.get()`.

Expand All @@ -15,6 +15,7 @@ Every queue operation is done in constant `O(1)` - including random access from
- [Why not use an Array?](#why-not-use-an-array)
- [Using double-ended queue as a normal queue](#using-double-ended-queue-as-a-normal-queue)
- [API reference and examples](#api)
- [Performance](#performance)

#Quick start

Expand Down Expand Up @@ -275,3 +276,18 @@ deque.toString(); //""

#Performance

Clone the repo and `npm install`. Then run the `bench` script.

##1000 items in the queue

double-ended-queue x 15,532,714 ops/sec ±0.19% (96 runs sampled)
built-in array x 6,501,398 ops/sec ±0.87% (95 runs sampled)
node-deque x 2,938,068 ops/sec ±3.50% (68 runs sampled)

##2 million items in the queue

double-ended-queue x 14,425,547 ops/sec ±0.17% (94 runs sampled)
node-deque x 2,815,628 ops/sec ±10.56% (76 runs sampled)
built-in array x 19.23 ops/sec ±0.35% (51 runs sampled)

Noteworthy is just how bad the degradation can be for built-in array when V8 cannot use the trick.
4 changes: 2 additions & 2 deletions bench
Expand Up @@ -5,6 +5,6 @@ cwd=${PWD}
trap 'cd "$cwd"' EXIT

cd "$cwd/benchmark"
node parser_runner.js
node stringify_runner.js
node thousand.js
node two_million.js
exit 0
36 changes: 0 additions & 36 deletions benchmark/parse.js

This file was deleted.

59 changes: 0 additions & 59 deletions benchmark/parser_runner.js

This file was deleted.

37 changes: 0 additions & 37 deletions benchmark/stringify.js

This file was deleted.

77 changes: 0 additions & 77 deletions benchmark/stringify_runner.js

This file was deleted.

73 changes: 73 additions & 0 deletions benchmark/thousand.js
@@ -0,0 +1,73 @@
var Benchmark = require("benchmark");
var Deque = require("../js/deque.js");
var NodeDeque= require("deque").Dequeue;
var DequeBuiltIn = Array;


function printPlatform() {
console.log("\nPlatform info:");
var os = require("os");
var v8 = process.versions.v8;
var node = process.versions.node;
var plat = os.type() + " " + os.release() + " " + os.arch() + "\nNode.JS " + node + "\nV8 " + v8;
var cpus = os.cpus().map(function(cpu){
return cpu.model;
}).reduce(function(o, model){
if( !o[model] ) o[model] = 0;
o[model]++;
return o;
}, {});
cpus = Object.keys(cpus).map(function( key ){
return key + " \u00d7 " + cpus[key];
}).join("\n");
console.log(plat + "\n" + cpus + "\n");
}

var deque = new Deque();
var nodeDeque = new NodeDeque();
var dequeBuiltIn = new DequeBuiltIn();

var l = 1000;

while(--l) {
deque.push(l);
nodeDeque.push(l);
dequeBuiltIn.push(l);
}

var suite = new Benchmark.Suite();

suite
.add("double-ended-queue", function(){
var a = deque.shift();
var b = deque.shift();
var c = deque.shift();

deque.push(a);
deque.push(b);
deque.push(c);
})
.add("node-deque", function(){
var a = nodeDeque.shift();
var b = nodeDeque.shift();
var c = nodeDeque.shift();

nodeDeque.push(a);
nodeDeque.push(b);
nodeDeque.push(c);
})
.add("built-in array", function(){
var a = dequeBuiltIn.shift();
var b = dequeBuiltIn.shift();
var c = dequeBuiltIn.shift();

dequeBuiltIn.push(a);
dequeBuiltIn.push(b);
dequeBuiltIn.push(c);
})
.on("cycle", function(e) {
console.log("" + e.target);
})
.run();


0 comments on commit 73fcc1c

Please sign in to comment.