Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bench.js 3.2KB

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