summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorGeo Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2024-04-12 18:31:00 +0300
committerGeo Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2024-04-12 18:31:00 +0300
commitb122279ece06a9381e805c6087f130b41616fe3d (patch)
tree2ec0a8fc3c570417d972b18a7a7b878758ce3a6f /benchmark
parent762d85c95690f510bec4dd8c37c05454ae1be4fc (diff)
downloadoseine-b122279ece06a9381e805c6087f130b41616fe3d.tar.gz
oseine-b122279ece06a9381e805c6087f130b41616fe3d.tar.bz2
oseine-b122279ece06a9381e805c6087f130b41616fe3d.zip
added utils folder; added several suplamentary modules
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/find.js27
-rw-r--r--benchmark/match-str.js22
2 files changed, 34 insertions, 15 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,
}
}
diff --git a/benchmark/match-str.js b/benchmark/match-str.js
index 7760b4e..fa802c1 100644
--- a/benchmark/match-str.js
+++ b/benchmark/match-str.js
@@ -1,17 +1,23 @@
-const products = require('../data/products.json');
-const match = require('../pieces/match-util.js');
var microtime = require('microtime');
+const match = require('../utils/match-util.js');
+const memory_usage = require('../utils/mem-usage.js');
+
+const products = require('../data/products.json');
-query = 'solokata';
+// memory_usage.report();
-function run() {
+// test runner
+function run(query) {
var f0 = microtime.nowDouble();
- // for(let i = 0 ; i < 100 ; i++)
- let result = matchQuery(query);
+ let result;
+ // for(let i = 0 ; i < 20 ; i++)
+ result = matchQuery(query);
var f1 = microtime.nowDouble();
+ memory_usage.report();
+
return {
t: f1-f0,
q: query,
@@ -19,7 +25,7 @@ function run() {
}
}
-
+// sumple search implementation
function matchQuery(q) {
var result = [];
@@ -43,4 +49,4 @@ function matchQuery(q) {
}
-module.exports = { run } \ No newline at end of file
+module.exports = { run }