summaryrefslogtreecommitdiff
path: root/benchmark/find.js
diff options
context:
space:
mode:
Diffstat (limited to 'benchmark/find.js')
-rw-r--r--benchmark/find.js27
1 files changed, 20 insertions, 7 deletions
diff --git a/benchmark/find.js b/benchmark/find.js
index cc95a44..2d18657 100644
--- a/benchmark/find.js
+++ b/benchmark/find.js
@@ -1,5 +1,11 @@
+/**
+ * benchmark: find a product in product list
+ * using: for vs forEach vs find
+ */
+
+const microtime = require('microtime');
+
const products = require('../data/products.json');
-var microtime = require('microtime');
var selected = [];
@@ -12,25 +18,32 @@ products.forEach( pr => {
function compare() {
+ let n = 4;
+
var f0 = microtime.nowDouble();
- for(i=0 ; i < 4 ; i++) byFor();
+ for(i=0 ; i < n ; i++) byFor();
var f1 = microtime.nowDouble();
//
var e0 = microtime.nowDouble();
- for(i=0 ; i < 4 ; i++) byEach();
+ for(i=0 ; i < n ; i++) byEach();
var e1 = microtime.nowDouble();
//
var b0 = microtime.nowDouble();
- for(i=0 ; i < 4 ; i++) byFind();
+ for(i=0 ; i < n ; i++) byFind();
var b1 = microtime.nowDouble();
return {
+ n: n,
+
for: f1-f0,
- ifor: byFor(),
+ items_for: byFor(),
+
each: e1-e0,
- ieach: byEach(),
+ items_each: byEach(),
+
find: b1-b0,
- ifind: byFind(),
+ items_find: byFind(),
+
sel: selected,
}
}