-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.ts
65 lines (57 loc) · 1.84 KB
/
benchmark.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import DynamoDB from 'aws-sdk/clients/dynamodb';
import {queryOptimized, queryRegular} from './src';
const ddb = new DynamoDB.DocumentClient({region: 'us-east-1'});
(async () => {
// warm up TCP connection
await testQueryRegular('hk5');
console.time('Regular query: <1 MB of items');
await testQueryRegular('hk5');
console.timeEnd('Regular query: <1 MB of items');
console.time('Optimized query: <1 MB of items');
await testQueryOptimized('hk5');
console.timeEnd('Optimized query: <1 MB of items');
console.time('Regular query: ~21 MB of items');
await testQueryRegular('hk6');
console.timeEnd('Regular query: ~21 MB of items');
console.time('Optimized query: ~21 MB of items');
await testQueryOptimized('hk6');
console.timeEnd('Optimized query: ~21 MB of items');
})();
function testQueryRegular(hash_key: string) {
return queryRegular({
queryFunction: ddb.query.bind(ddb),
queryParams: {
TableName: 'ddb-query-optimized',
ProjectionExpression: 'hash_key, range_key',
KeyConditionExpression: '#hash_key = :hash_key',
FilterExpression: '#number > :number',
ExpressionAttributeNames: {
'#hash_key': 'hash_key',
'#number': 'number',
},
ExpressionAttributeValues: {
':hash_key': hash_key,
':number': 0.5,
},
},
});
}
function testQueryOptimized(hash_key: string) {
return queryOptimized({
queryFunction: ddb.query.bind(ddb),
queryParams: {
TableName: 'ddb-query-optimized',
ProjectionExpression: 'hash_key, range_key',
KeyConditionExpression: '#hash_key = :hash_key',
FilterExpression: '#number > :number',
ExpressionAttributeNames: {
'#hash_key': 'hash_key',
'#number': 'number',
},
ExpressionAttributeValues: {
':hash_key': hash_key,
':number': 0.5,
},
},
});
}