프로젝트

일반

사용자정보

통계
| 개정판:

root / HServer / 00.Server / 00.Program / node_modules / mpath / bench.js

이력 | 보기 | 이력해설 | 다운로드 (3.22 KB)

1 39 HKM
2
var mpath = require('./')
3
var Bench = require('benchmark');
4
var sha = require('child_process').exec("git log --pretty=format:'%h' -n 1", function (err, sha) {
5
  if (err) throw err;
6
7
  var fs = require('fs')
8
  var filename = __dirname + '/bench.out';
9
  var out = fs.createWriteStream(filename, { flags: 'a', encoding: 'utf8' });
10
11
  /**
12
   * test doc creator
13
   */
14
15
  function doc () {
16
    var o = { first: { second: { third: [3,{ name: 'aaron' }, 9] }}};
17
    o.comments = [
18
        { name: 'one' }
19
      , { name: 'two', _doc: { name: '2' }}
20
      , { name: 'three'
21
          , comments: [{},{ comments: [{val: 'twoo'}]}]
22
          , _doc: { name: '3', comments: [{},{ _doc: { comments: [{ val: 2 }] }}]  }}
23
    ];
24
    o.name = 'jiro';
25
    o.array = [
26
        { o: { array: [{x: {b: [4,6,8]}}, { y: 10} ] }}
27
      , { o: { array: [{x: {b: [1,2,3]}}, { x: {z: 10 }}, { x: {b: 'hi'}}] }}
28
      , { o: { array: [{x: {b: null }}, { x: { b: [null, 1]}}] }}
29
      , { o: { array: [{x: null }] }}
30
      , { o: { array: [{y: 3 }] }}
31
      , { o: { array: [3, 0, null] }}
32
      , { o: { name: 'ha' }}
33
    ];
34
    o.arr = [
35
        { arr: [{ a: { b: 47 }}, { a: { c: 48 }}, { d: 'yep' }] }
36
      , { yep: true }
37
    ]
38
    return o;
39
  }
40
41
  var o = doc();
42
43
  var s = new Bench.Suite;
44
  s.add('mpath.get("first", obj)', function () {
45
    mpath.get('first', o);
46
  })
47
  s.add('mpath.get("first.second", obj)', function () {
48
    mpath.get('first.second', o);
49
  })
50
  s.add('mpath.get("first.second.third.1.name", obj)', function () {
51
    mpath.get('first.second.third.1.name', o);
52
  })
53
  s.add('mpath.get("comments", obj)', function () {
54
    mpath.get('comments', o);
55
  })
56
  s.add('mpath.get("comments.1", obj)', function () {
57
    mpath.get('comments.1', o);
58
  })
59
  s.add('mpath.get("comments.2.name", obj)', function () {
60
    mpath.get('comments.2.name', o);
61
  })
62
  s.add('mpath.get("comments.2.comments.1.comments.0.val", obj)', function () {
63
    mpath.get('comments.2.comments.1.comments.0.val', o);
64
  })
65
  s.add('mpath.get("comments.name", obj)', function () {
66
    mpath.get('comments.name', o);
67
  })
68
69
  s.add('mpath.set("first", obj, val)', function () {
70
    mpath.set('first', o, 1);
71
  })
72
  s.add('mpath.set("first.second", obj, val)', function () {
73
    mpath.set('first.second', o, 1);
74
  })
75
  s.add('mpath.set("first.second.third.1.name", obj, val)', function () {
76
    mpath.set('first.second.third.1.name', o, 1);
77
  })
78
  s.add('mpath.set("comments", obj, val)', function () {
79
    mpath.set('comments', o, 1);
80
  })
81
  s.add('mpath.set("comments.1", obj, val)', function () {
82
    mpath.set('comments.1', o, 1);
83
  })
84
  s.add('mpath.set("comments.2.name", obj, val)', function () {
85
    mpath.set('comments.2.name', o, 1);
86
  })
87
  s.add('mpath.set("comments.2.comments.1.comments.0.val", obj, val)', function () {
88
    mpath.set('comments.2.comments.1.comments.0.val', o, 1);
89
  })
90
  s.add('mpath.set("comments.name", obj, val)', function () {
91
    mpath.set('comments.name', o, 1);
92
  })
93
94
  s.on('start', function () {
95
    console.log('starting...');
96
    out.write('*' + sha + ': ' + String(new Date()) + '\n');
97
  });
98
  s.on('cycle', function (e) {
99
    var s = String(e.target);
100
    console.log(s);
101
    out.write(s + '\n');
102
  })
103
  s.on('complete', function () {
104
    console.log('done')
105
    out.end('');
106
  })
107
  s.run()
108
})