-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrust-nostr.bench.ts
66 lines (48 loc) · 1.18 KB
/
rust-nostr.bench.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
66
import {
EventBuilder,
Keys,
loadWasmAsync,
loadWasmSync,
} from "npm:@rust-nostr/nostr";
import { finalizeEvent } from "nostr-tools";
import { hexToBytes } from "npm:@noble/hashes/utils";
import { Event } from "npm:@rust-nostr/nostr";
Deno.bench("loadWasmSync", () => {
loadWasmSync();
});
Deno.bench("loadWasmAsync", async () => {
await loadWasmAsync();
});
Deno.bench("generate", async (b) => {
await loadWasmAsync();
b.start();
Keys.generate();
b.end();
});
Deno.bench("toEvent", async (b) => {
await loadWasmAsync();
const keys = Keys.generate();
b.start();
new EventBuilder(1, "", []).toEvent(keys).asJson();
b.end();
});
Deno.bench("verify", async (b) => {
await loadWasmAsync();
const keys = Keys.generate();
const event = new EventBuilder(1, "", []).toEvent(keys);
b.start();
event.verify();
b.end();
});
Deno.bench("verify with fromJson", async (b) => {
await loadWasmAsync();
const keys = Keys.generate();
const event = finalizeEvent(
{ kind: 1, content: "", tags: [], created_at: 0 },
hexToBytes(keys.secretKey.toHex()),
);
b.start();
const json = JSON.stringify(event);
Event.fromJson(json).verify();
b.end();
});