summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/match-str.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/benchmark/match-str.js b/benchmark/match-str.js
new file mode 100644
index 0000000..7760b4e
--- /dev/null
+++ b/benchmark/match-str.js
@@ -0,0 +1,46 @@
+const products = require('../data/products.json');
+const match = require('../pieces/match-util.js');
+var microtime = require('microtime');
+
+
+query = 'solokata';
+
+function run() {
+
+ var f0 = microtime.nowDouble();
+ // for(let i = 0 ; i < 100 ; i++)
+ let result = matchQuery(query);
+ var f1 = microtime.nowDouble();
+
+ return {
+ t: f1-f0,
+ q: query,
+ result: result
+ }
+}
+
+
+function matchQuery(q) {
+ var result = [];
+
+ for(let i = 0; i < products.length; i++) {
+ let found = false;
+ let similarity = 0;
+ products[i].kb.split(' ').forEach( w => {
+ let sim = match.resemblance(q, w, 2);
+ if (sim > 0.5) {
+ found = true;
+ similarity = (sim > similarity) ? sim : similarity;
+ }
+ });
+ if (found) {
+ products[i].similarity = similarity;
+ result.push(products[i]);
+ }
+ }
+
+ return result
+}
+
+
+module.exports = { run } \ No newline at end of file