Skip to content

Commit d2412c7

Browse files
committed
Add benchmark project
Signed-off-by: moznion <moznion@mail.moznion.net>
1 parent 53dc317 commit d2412c7

File tree

8 files changed

+2443
-0
lines changed

8 files changed

+2443
-0
lines changed

examples/benchmark/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
using_transformer.js
2+

examples/benchmark/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# benchmark
2+
3+
This project does benchmark of object marshalling into DynamoDB atributes between ts-dynamodb-attributes-transformer and [kayomarz/dynamodb-data-types](https://github.com/kayomarz/dynamodb-data-types).
4+
5+
## How to run
6+
7+
```
8+
npm ci
9+
npm run bench
10+
```
11+
12+
## Example result
13+
14+
```
15+
node version: v16.17.0
16+
dynamodb-data-types marshalling x 3,475,450 ops/sec ±0.45% (96 runs sampled)
17+
ts-dynamodb-attributes-transformer marshalling x 13,405,409 ops/sec ±0.43% (91 runs sampled)
18+
Fastest is ts-dynamodb-attributes-transformer marshalling
19+
```
20+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const AttributeValue = require('dynamodb-data-types').AttributeValue;
2+
3+
const obj = {
4+
id: 12345,
5+
name: 'John Doe',
6+
tags: {
7+
foo: 'bar',
8+
buz: 'qux',
9+
},
10+
flags: ['foo', 'bar'],
11+
nil: null,
12+
};
13+
14+
function toDynamoDBRecord() {
15+
AttributeValue.wrap(obj);
16+
}
17+
18+
module.exports = toDynamoDBRecord;

examples/benchmark/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const Benchmark = require('benchmark');
2+
const toDynamoDBRecordByDataTypes = require('./dynamodb_data_types');
3+
const toDynamoDBRecordByTransformer = require('./using_transformer').toDynamoDBRecord;
4+
5+
console.log(`node version: ${process.version}`);
6+
new Benchmark.Suite()
7+
.add('dynamodb-data-types marshalling', function () {
8+
toDynamoDBRecordByDataTypes();
9+
})
10+
.add('ts-dynamodb-attributes-transformer marshalling', function () {
11+
toDynamoDBRecordByTransformer();
12+
})
13+
.on('cycle', function (event) {
14+
console.log(String(event.target));
15+
})
16+
.on('complete', function () {
17+
console.log('Fastest is ' + this.filter('fastest').map('name'));
18+
})
19+
.run({ async: true });

0 commit comments

Comments
 (0)