From fe8bdc67870e939a527813f1916fc66d1a56a2c1 Mon Sep 17 00:00:00 2001 From: Pedro Nascimento Date: Wed, 22 Apr 2020 10:09:36 -0300 Subject: [PATCH] chore: add benchmarks --- benchmark/.gitignore | 1 + benchmark/cpf.js | 4 ++++ benchmark/cpf_check.js | 4 ++++ benchmark/fnando_cpf.js | 4 ++++ benchmark/package.json | 21 +++++++++++++++++++++ benchmark/testUtil.js | 12 ++++++++++++ benchmark/wasm.js | 4 ++++ benchmark/yarn.lock | 23 +++++++++++++++++++++++ 8 files changed, 73 insertions(+) create mode 100644 benchmark/.gitignore create mode 100644 benchmark/cpf.js create mode 100644 benchmark/cpf_check.js create mode 100644 benchmark/fnando_cpf.js create mode 100644 benchmark/package.json create mode 100644 benchmark/testUtil.js create mode 100644 benchmark/wasm.js create mode 100644 benchmark/yarn.lock diff --git a/benchmark/.gitignore b/benchmark/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/benchmark/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/benchmark/cpf.js b/benchmark/cpf.js new file mode 100644 index 0000000..10198c7 --- /dev/null +++ b/benchmark/cpf.js @@ -0,0 +1,4 @@ +const { isValid } = require('cpf'); +const { testUtil } = require('./testUtil'); + +testUtil(isValid); diff --git a/benchmark/cpf_check.js b/benchmark/cpf_check.js new file mode 100644 index 0000000..5da8657 --- /dev/null +++ b/benchmark/cpf_check.js @@ -0,0 +1,4 @@ +const cpfCheck = require('cpf-check'); +const { testUtil } = require('./testUtil'); + +testUtil(cpfCheck.validate); diff --git a/benchmark/fnando_cpf.js b/benchmark/fnando_cpf.js new file mode 100644 index 0000000..9ca1f5b --- /dev/null +++ b/benchmark/fnando_cpf.js @@ -0,0 +1,4 @@ +const { isValid } = require('@fnando/cpf'); +const { testUtil } = require('./testUtil'); + +testUtil(isValid); diff --git a/benchmark/package.json b/benchmark/package.json new file mode 100644 index 0000000..060d7e2 --- /dev/null +++ b/benchmark/package.json @@ -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" + } +} diff --git a/benchmark/testUtil.js b/benchmark/testUtil.js new file mode 100644 index 0000000..4f6102b --- /dev/null +++ b/benchmark/testUtil.js @@ -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 }; diff --git a/benchmark/wasm.js b/benchmark/wasm.js new file mode 100644 index 0000000..fc9becd --- /dev/null +++ b/benchmark/wasm.js @@ -0,0 +1,4 @@ +const { isValid } = require('cpf-wasm'); +const { testUtil } = require('./testUtil'); + +testUtil(isValid); diff --git a/benchmark/yarn.lock b/benchmark/yarn.lock new file mode 100644 index 0000000..9eb371e --- /dev/null +++ b/benchmark/yarn.lock @@ -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==