diff options
| author | Geo Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2024-04-12 18:31:00 +0300 |
|---|---|---|
| committer | Geo Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2024-04-12 18:31:00 +0300 |
| commit | b122279ece06a9381e805c6087f130b41616fe3d (patch) | |
| tree | 2ec0a8fc3c570417d972b18a7a7b878758ce3a6f /benchmark/find.js | |
| parent | 762d85c95690f510bec4dd8c37c05454ae1be4fc (diff) | |
| download | oseine-b122279ece06a9381e805c6087f130b41616fe3d.tar.gz oseine-b122279ece06a9381e805c6087f130b41616fe3d.tar.bz2 oseine-b122279ece06a9381e805c6087f130b41616fe3d.zip | |
added utils folder; added several suplamentary modules
Diffstat (limited to 'benchmark/find.js')
| -rw-r--r-- | benchmark/find.js | 27 |
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, } } |
