Skip to content

Commit

Permalink
chore: add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrolcn committed Apr 22, 2020
1 parent c38fd2d commit fe8bdc6
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
4 changes: 4 additions & 0 deletions benchmark/cpf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { isValid } = require('cpf');
const { testUtil } = require('./testUtil');

testUtil(isValid);
4 changes: 4 additions & 0 deletions benchmark/cpf_check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const cpfCheck = require('cpf-check');
const { testUtil } = require('./testUtil');

testUtil(cpfCheck.validate);
4 changes: 4 additions & 0 deletions benchmark/fnando_cpf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { isValid } = require('@fnando/cpf');
const { testUtil } = require('./testUtil');

testUtil(isValid);
21 changes: 21 additions & 0 deletions benchmark/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "benchmark",
"version": "0.2.2",
"description": "cpf-wasm benchmars",
"main": "index.js",
"author": "Pedro Nascimento",
"license": "MIT",
"private": false,
"scripts": {
"benchmark:wasm": "time node wasm",
"benchmark:cpf": "time node cpf",
"benchmark:fnando-cpf": "time node fnando_cpf",
"benchmark:cpf-check": "time node cpf_check"
},
"dependencies": {
"@fnando/cpf": "^1.0.1",
"cpf": "^2.0.1",
"cpf-check": "^3.0.0",
"cpf-wasm": "^0.1.1"
}
}
12 changes: 12 additions & 0 deletions benchmark/testUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function testUtil(test_closure) {
const TEST_CPF_COUNT = 10000000;
const ONE_PERCENT = TEST_CPF_COUNT/100;

for (let i=0; i< TEST_CPF_COUNT; i += 1) {
if (i % ONE_PERCENT === 0) console.log(`${i/ONE_PERCENT} %`);
const cpfString = i.toString().padStart(11, '0');
test_closure(cpfString);
}
}

module.exports = { testUtil };
4 changes: 4 additions & 0 deletions benchmark/wasm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { isValid } = require('cpf-wasm');
const { testUtil } = require('./testUtil');

testUtil(isValid);
23 changes: 23 additions & 0 deletions benchmark/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@fnando/cpf@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@fnando/cpf/-/cpf-1.0.1.tgz#59838dc8dcf5e6f9e6fa6022b3411593a733f0e7"
integrity sha512-7KdgB+x/825Wk0/qiud0U1QmJQydSBvH/0X8SQ9pAuOzhfzwH1Xsgd6efQFILgFcxE0QvNfYu2HadpPmsUzlgQ==

cpf-check@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/cpf-check/-/cpf-check-3.0.0.tgz#7279a1f6998a9385da1386bbe427fbf78144b9ec"
integrity sha512-IwUJdDJ57kheRXiO7govTBOcKsLK/AdDrVKfk6rYCCNDcOBUiY9zmUY0fWI4/S/oIpbhHWMcOD0O2DLawuwiBw==

cpf-wasm@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/cpf-wasm/-/cpf-wasm-0.1.1.tgz#7313460b675ec6ad71b737435dfadd4ae7f5cf96"
integrity sha512-GqfZcPF/Oz837ArJO2KnSqXMU5qejMeyMLRLz+Vmys+Wo7FjEBSnxggSmOynNvB8/w6c4nZw9aU7FRLwUKtYGg==

cpf@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/cpf/-/cpf-2.0.1.tgz#7979eb33f0a14e8217292944311faaba82cb7f02"
integrity sha512-YpRbrpjQCDkZgMUOLxLfme8wE8X56fHXOGMGDsYA48f7UrjaCHU0TP8d+CKmxvNVjBDVtHiCUiBw8vfstdslbw==

0 comments on commit fe8bdc6

Please sign in to comment.