|
| 1 | +const { readFileSync } = require('fs') |
| 2 | +const { join } = require('path') |
| 3 | + |
| 4 | +const { Suite } = require('benchmark') |
| 5 | +const chalk = require('chalk') |
| 6 | +const { h32: h32js, h64: h64js } = require('xxhashjs') |
| 7 | + |
| 8 | +const { xxh32, xxh64, Xxh32, Xxh64 } = require('../index') |
| 9 | + |
| 10 | +const FX = readFileSync(join(__dirname, '..', '..', '..', 'yarn.lock')) |
| 11 | + |
| 12 | +new Suite('xxh32') |
| 13 | + .add('@node-rs/xxhash h32', () => { |
| 14 | + xxh32(FX) |
| 15 | + }) |
| 16 | + .add('xxhashjs h32', () => { |
| 17 | + h32js(FX, 0).toNumber() |
| 18 | + }) |
| 19 | + .on('cycle', function (event) { |
| 20 | + console.info(String(event.target)) |
| 21 | + }) |
| 22 | + .on('complete', function () { |
| 23 | + console.info(`${this.name} bench suite: Fastest is ${chalk.green(this.filter('fastest').map('name'))}`) |
| 24 | + }) |
| 25 | + .run() |
| 26 | + |
| 27 | +new Suite('xxh32 multi steps') |
| 28 | + .add('@node-rs/xxhash h32', () => { |
| 29 | + new Xxh32().update(FX).digest() |
| 30 | + }) |
| 31 | + .add('xxhashjs h32', () => { |
| 32 | + h32js().update(FX).digest().toNumber() |
| 33 | + }) |
| 34 | + .on('cycle', function (event) { |
| 35 | + console.info(String(event.target)) |
| 36 | + }) |
| 37 | + .on('complete', function () { |
| 38 | + console.info(`${this.name} bench suite: Fastest is ${chalk.green(this.filter('fastest').map('name'))}`) |
| 39 | + }) |
| 40 | + .run() |
| 41 | + |
| 42 | +new Suite('xxh64') |
| 43 | + .add('@node-rs/xxhash 64', () => { |
| 44 | + xxh64(FX).toString(16) |
| 45 | + }) |
| 46 | + .add('xxhashjs h64', () => { |
| 47 | + h64js(FX, 0).toString(16) |
| 48 | + }) |
| 49 | + .on('cycle', function (event) { |
| 50 | + console.info(String(event.target)) |
| 51 | + }) |
| 52 | + .on('complete', function () { |
| 53 | + console.info(`${this.name} bench suite: Fastest is ${chalk.green(this.filter('fastest').map('name'))}`) |
| 54 | + }) |
| 55 | + .run() |
| 56 | + |
| 57 | +new Suite('xxh64 multi steps') |
| 58 | + .add('@node-rs/xxhash 64', () => { |
| 59 | + new Xxh64().update(FX).digest().toString(16) |
| 60 | + }) |
| 61 | + .add('xxhashjs h64', () => { |
| 62 | + h64js(0).update(FX).digest().toString(16) |
| 63 | + }) |
| 64 | + .on('cycle', function (event) { |
| 65 | + console.info(String(event.target)) |
| 66 | + }) |
| 67 | + .on('complete', function () { |
| 68 | + console.info(`${this.name} bench suite: Fastest is ${chalk.green(this.filter('fastest').map('name'))}`) |
| 69 | + }) |
| 70 | + .run() |
0 commit comments