Skip to content

Commit 3b0fee2

Browse files
committed
feat: add moment benchmark
1 parent 179c36d commit 3b0fee2

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ packages operations.
1010
- [x] prettier
1111
- [ ] webpack
1212
- [x] babel
13-
- [ ] moment
13+
- [x] moment
1414
- [ ] dotenv
1515
- [ ] pinojs
1616
- [ ] winston

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const path = require('node:path');
33
const Piscina = require('piscina');
44

55
const piscina = new Piscina({
6-
filename: path.resolve(__dirname, 'worker.js')
6+
filename: path.resolve(__dirname, 'worker.js'),
7+
maxQueue: 1,
78
});
89

910
async function main() {
@@ -14,7 +15,6 @@ async function main() {
1415
const result = await piscina.run(benchFile);
1516
console.log('results', JSON.stringify(result, null, 2));
1617
}
17-
console.log('Done...', file)
1818
}
1919
}
2020

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"@babel/standalone": "7.24.0",
44
"fastify": "4.26.1",
55
"lodash": "4.17.21",
6+
"moment": "2.30.1",
67
"piscina": "4.4.0",
78
"prettier": "3.2.5"
89
},

pnpm-lock.yaml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/moment-benchmark.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const moment = require('moment');
2+
3+
module.exports = {
4+
name: 'moment',
5+
type: 'operation',
6+
operations: [
7+
{
8+
name: 'format (full)',
9+
fn: () => {
10+
return moment().format('MMMM Do YYYY, h:mm:ss a');
11+
},
12+
},
13+
{
14+
name: 'format',
15+
fn: () => {
16+
return moment().format();
17+
},
18+
},
19+
{
20+
name: 'fromNow (YYYYMMDD)',
21+
fn: () => {
22+
return moment('20111031', 'YYYYMMDD').fromNow();
23+
},
24+
},
25+
{
26+
name: 'subtract (10)',
27+
fn: () => {
28+
return moment().subtract(10, 'days').calendar();
29+
},
30+
},
31+
],
32+
benchmarker: 'benchmarkjs',
33+
};

0 commit comments

Comments
 (0)