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.

38 lines
713 B

2 years ago
  1. 'use strict'
  2. var reusify = require('../')
  3. var fib = require('./fib')
  4. var instance = reusify(MyObject)
  5. var max = 100000000
  6. var start = Date.now()
  7. function reuseNoCodeFunction () {
  8. var obj = instance.get()
  9. obj.num = 100
  10. obj.func()
  11. obj.num = 0
  12. instance.release(obj)
  13. }
  14. function MyObject () {
  15. this.next = null
  16. var that = this
  17. this.num = 0
  18. this.func = function () {
  19. /* eslint no-constant-condition: "off" */
  20. if (null) {
  21. // do nothing
  22. } else {
  23. fib(that.num)
  24. }
  25. }
  26. }
  27. for (var i = 0; i < max; i++) {
  28. reuseNoCodeFunction()
  29. }
  30. var time = Date.now() - start
  31. console.log('Total time', time)
  32. console.log('Total iterations', max)
  33. console.log('Iteration/s', max / time * 1000)