index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* eslint-disable no-unused-expressions */
  2. var bench = require('nanobench')
  3. var acornsrc = require('fs').readFileSync(require.resolve('acorn'))
  4. var lodashsrc = require('fs').readFileSync(require.resolve('lodash'))
  5. var jquerysrc = require('fs').readFileSync(require.resolve('jquery'))
  6. var threesrc = require('fs').readFileSync(require.resolve('three'))
  7. var find = require('../')
  8. // Optimize.
  9. for (var i = 0; i < 5; i++) find(acornsrc).properties
  10. // Has very few undeclared identifiers
  11. bench('acorn × 1', function (b) {
  12. b.start()
  13. find(acornsrc).properties
  14. b.end()
  15. })
  16. bench('acorn × 5', function (b) {
  17. b.start()
  18. for (var i = 0; i < 5; i++) find(acornsrc).properties
  19. b.end()
  20. })
  21. bench('lodash × 1', function (b) {
  22. b.start()
  23. find(lodashsrc).properties
  24. b.end()
  25. })
  26. bench('lodash × 5', function (b) {
  27. b.start()
  28. for (var i = 0; i < 5; i++) find(lodashsrc).properties
  29. b.end()
  30. })
  31. // Has more undeclared identifiers and properties
  32. bench('jquery × 1', function (b) {
  33. b.start()
  34. find(jquerysrc).properties
  35. b.end()
  36. })
  37. bench('jquery × 5', function (b) {
  38. b.start()
  39. for (var i = 0; i < 5; i++) find(jquerysrc).properties
  40. b.end()
  41. })
  42. // is very large
  43. bench('three × 1', function (b) {
  44. b.start()
  45. find(threesrc).identifiers
  46. b.end()
  47. })
  48. bench('three × 5', function (b) {
  49. b.start()
  50. for (var i = 0; i < 5; i++) find(threesrc).identifiers
  51. b.end()
  52. })