-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from jojoee/feature/increase-performance
Feature/increase performance
- Loading branch information
Showing
3 changed files
with
53 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const { bahttext } = require('./src') | ||
const THBText = require('thai-baht-text') | ||
const { ThaiBaht } = require('thai-baht-text-ts') | ||
const { convert } = require('baht') | ||
|
||
const allTestcases = require('./misc/testcases.json') | ||
const nTestCases = allTestcases.length | ||
const testcases = allTestcases.slice(0, nTestCases) | ||
const numbers = testcases.map(item => parseFloat(item.number)) | ||
const nIterations = 10000 | ||
|
||
const testedLib = { | ||
bahttext: n => bahttext(n), | ||
baht: n => convert(n), | ||
'thai-baht-text': n => THBText(n), | ||
'thai-baht-text-ts': n => ThaiBaht(n) | ||
} | ||
|
||
Object.entries(testedLib).forEach(([name, fn]) => { | ||
const start = new Date() | ||
|
||
new Array(nIterations).fill(0).forEach(_ => { | ||
numbers.forEach(number => fn(number)) | ||
}) | ||
|
||
const end = new Date() | ||
const elapsed = end - start | ||
console.log(`${name}: elapsed: ${elapsed} ms, start: ${start.toISOString()}, end: ${end.toISOString()}`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters