escape.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. var benchmark = require('benchmark');
  2. var benchmarks = require('beautify-benchmark');
  3. global.SqlString = require('..');
  4. global.arr = [ 42, 'foobar' ];
  5. global.buf = new Buffer('foobar');
  6. global.date = new Date(0);
  7. global.func = { toSqlString: function () { return 'NOW()'; } };
  8. global.num = 42;
  9. global.obj = { foo: 'bar' };
  10. global.str = 'foobar';
  11. var suite = new benchmark.Suite();
  12. suite.add({
  13. name : 'array',
  14. minSamples : 100,
  15. fn : 'var val = SqlString.escape(arr);'
  16. });
  17. suite.add({
  18. name : 'boolean',
  19. minSamples : 100,
  20. fn : 'var val = SqlString.escape(true);'
  21. });
  22. suite.add({
  23. name : 'date',
  24. minSamples : 100,
  25. fn : 'var val = SqlString.escape(date);'
  26. });
  27. suite.add({
  28. name : 'function',
  29. minSamples : 100,
  30. fn : 'var val = SqlString.escape(func);'
  31. });
  32. suite.add({
  33. name : 'null',
  34. minSamples : 100,
  35. fn : 'var val = SqlString.escape(null);'
  36. });
  37. suite.add({
  38. name : 'number',
  39. minSamples : 100,
  40. fn : 'var val = SqlString.escape(num);'
  41. });
  42. suite.add({
  43. name : 'object',
  44. minSamples : 100,
  45. fn : 'var val = SqlString.escape(obj);'
  46. });
  47. suite.add({
  48. name : 'string',
  49. minSamples : 100,
  50. fn : 'var val = SqlString.escape(str);'
  51. });
  52. suite.on('start', function onCycle() {
  53. process.stdout.write(' escape\n\n');
  54. });
  55. suite.on('cycle', function onCycle(event) {
  56. benchmarks.add(event.target);
  57. });
  58. suite.on('complete', function onComplete() {
  59. benchmarks.log();
  60. });
  61. suite.run({async: false});