bench.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. function bench (fn, n) {
  2. var s = Date.now()
  3. var vms = []
  4. for (var i = 0; i < n; i++) {
  5. vms.push(fn())
  6. }
  7. console.log(n + ' ' + fn.desciption + ': ' + (Date.now() - s) + 'ms')
  8. }
  9. function emptyInstance () {
  10. return new Vue()
  11. }
  12. emptyInstance.desciption = 'empty instances'
  13. var options = {
  14. template: '{{hi}}',
  15. data: function () {
  16. return {
  17. hi: 'msg'
  18. }
  19. },
  20. ready: function () {},
  21. filters: {
  22. that: function () {}
  23. }
  24. }
  25. function instanceWithOption () {
  26. return new Vue(options)
  27. }
  28. instanceWithOption.desciption = 'instance with options'
  29. var Test = Vue.extend(options)
  30. function extendedInstance () {
  31. return new Test()
  32. }
  33. extendedInstance.desciption = 'extended instances'
  34. function extendedInstanceWithOptions () {
  35. return new Test({
  36. data: function () {
  37. return {
  38. b: 'lol'
  39. }
  40. },
  41. ready: function () {},
  42. directives: {
  43. that: function () {
  44. }
  45. }
  46. })
  47. }
  48. extendedInstanceWithOptions.desciption = 'extended instances with options'
  49. bench(emptyInstance, 100)
  50. bench(emptyInstance, 1000)
  51. bench(emptyInstance, 10000)
  52. bench(instanceWithOption, 100)
  53. bench(instanceWithOption, 1000)
  54. bench(instanceWithOption, 10000)
  55. bench(extendedInstance, 100)
  56. bench(extendedInstance, 1000)
  57. bench(extendedInstance, 10000)
  58. bench(extendedInstanceWithOptions, 100)
  59. bench(extendedInstanceWithOptions, 1000)
  60. bench(extendedInstanceWithOptions, 10000)
  61. // TODO:
  62. //
  63. // - rendering performance
  64. // - simple v-repeat
  65. // - component v-repeat
  66. // - v-repeat with nested components
  67. //
  68. // - data observation performance
  69. // - simple objects
  70. // - complex objects
  71. // - small array
  72. // - large array
  73. //
  74. // - dependency tracking performance
  75. // - simple watcher
  76. // - complex watcher