Evan You 11 år sedan
förälder
incheckning
ff1329b838
5 ändrade filer med 29 tillägg och 13 borttagningar
  1. 2 1
      .gitignore
  2. 7 3
      benchmarks/observer.js
  3. 1 0
      benchmarks/runner.html
  4. 14 7
      gruntfile.js
  5. 5 2
      tasks/bench.js

+ 2 - 1
.gitignore

@@ -2,4 +2,5 @@ dist/vue.min.js.gz
 test/vue.test.js
 explorations
 node_modules
-.DS_Store
+.DS_Store
+benchmarks/browser.js

+ 7 - 3
benchmarks/observer.js

@@ -1,3 +1,5 @@
+console.log('\nObserver\n')
+
 var Observer = require('../src/observer/observer')
 var Emitter = require('../src/emitter')
 var OldObserver = require('../../vue/src/observer')
@@ -7,15 +9,17 @@ function cb () {
   sideEffect = !sideEffect
 }
 
-var loadTime = getNano()
-
 function getNano () {
   var hr = process.hrtime()
   return hr[0] * 1e9 + hr[1]
 }
 
 function now () {
-  return (getNano() - loadTime) / 1e6
+  return process.hrtime
+    ? getNano() / 1e6
+    : window.performence
+      ? window.performence.now()
+      : Date.now()
 }
 
 function bench (desc, fac, run) {

+ 1 - 0
benchmarks/runner.html

@@ -0,0 +1 @@
+<script src="browser.js"></script>

+ 14 - 7
gruntfile.js

@@ -46,22 +46,29 @@ module.exports = function (grunt) {
     },
 
     browserify: {
-      options: {
-        bundleOptions: {
-          standalone: 'Vue'
-        }
-      },
       build: {
         src: ['src/vue.js'],
-        dest: 'dist/vue.js'
+        dest: 'dist/vue.js',
+        options: {
+          bundleOptions: {
+            standalone: 'Vue'
+          }
+        }
       },
       watch: {
         src: ['src/vue.js'],
         dest: 'dist/vue.js',
         options: {
           watch: true,
-          keepAlive: true
+          keepAlive: true,
+          bundleOptions: {
+            standalone: 'Vue'
+          }
         }
+      },
+      bench: {
+        src: ['benchmarks/*.js', '!benchmarks/browser.js'],
+        dest: 'benchmarks/browser.js'
       }
     }
 

+ 5 - 2
tasks/bench.js

@@ -1,3 +1,7 @@
+/**
+ * Run benchmarks in Node
+ */
+
 module.exports = function (grunt) {
   grunt.registerTask('bench', function () {
 
@@ -13,8 +17,7 @@ module.exports = function (grunt) {
     require('fs')
       .readdirSync('./benchmarks')
       .forEach(function (mod) {
-        if (mod === 'run.js') return
-        console.log('\n' + mod.slice(0, -3).toUpperCase() + '\n')
+        if (mod === 'browser.js' || mod === 'runner.html') return
         require('../benchmarks/' + mod)
       })