Welcome to mirror list, hosted at ThFree Co, Russian Federation.

compare_v1.js « test « node-uuid « node_modules « request « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 05af82215fd82a212f250d55ed69349ad45f6c4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var assert = require('assert'),
    nodeuuid = require('../uuid'),
    uuidjs = require('uuid-js'),
    libuuid = require('uuid').generate,
    util = require('util'),
    exec = require('child_process').exec,
    os = require('os');

// On Mac Os X / macports there's only the ossp-uuid package that provides uuid
// On Linux there's uuid-runtime which provides uuidgen
var uuidCmd = os.type() === 'Darwin' ? 'uuid -1' : 'uuidgen -t';

function compare(ids) {
  console.log(ids);
  for (var i = 0; i < ids.length; i++) {
    var id = ids[i].split('-');
    id = [id[2], id[1], id[0]].join('');
    ids[i] = id;
  }
  var sorted = ([].concat(ids)).sort();

  if (sorted.toString() !== ids.toString()) {
    console.log('Warning: sorted !== ids');
  } else {
    console.log('everything in order!');
  }
}

// Test time order of v1 uuids
var ids = [];
while (ids.length < 10e3) ids.push(nodeuuid.v1());

var max = 10;
console.log('node-uuid:');
ids = [];
for (var i = 0; i < max; i++) ids.push(nodeuuid.v1());
compare(ids);

console.log('');
console.log('uuidjs:');
ids = [];
for (var i = 0; i < max; i++) ids.push(uuidjs.create(1).toString());
compare(ids);

console.log('');
console.log('libuuid:');
ids = [];
var count = 0;
var last = function() {
  compare(ids);
}
var cb = function(err, stdout, stderr) {
  ids.push(stdout.substring(0, stdout.length-1));
  count++;
  if (count < max) {
    return next();
  }
  last();
};
var next = function() {
  exec(uuidCmd, cb);
};
next();