Skip to content

Commit

Permalink
use perf.now()
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGruber committed Nov 15, 2024
1 parent 3f2d9a0 commit 75d8183
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions benches/js-bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ function bench(name: string, func: any) {
for (let i = 0; i < 100; i++) {
func();
}
console.time(name);
const start = performance.now();
func();
console.timeEnd(name);
const end = performance.now();
console.log(`${name} : ${end - start}ms`);
}

console.time("Init Protocol");
Expand Down Expand Up @@ -142,9 +143,9 @@ bench("Pack Session Request", () => {
});

bench("Pack Session Request DIRECT ACCESS", () => {
soeProtocol.pack_session_request_packet(1008176227,3,512,"LoginUdp_9");
soeProtocol.pack_session_request_packet(1008176227, 3, 512, "LoginUdp_9");
});
const mdddrrr = JSON.parse(sessionRequestToPack)
const mdddrrr = JSON.parse(sessionRequestToPack);
bench("Pack Session Request JS", () => {
soeProtocol.pack_session_request_fromjs(mdddrrr);
});
Expand All @@ -154,7 +155,7 @@ bench("Pack Session Reply", () => {
});

bench("Pack Session Reply DIRECT ACCESS", () => {
soeProtocol.pack_session_reply_packet(1008176227,0,2,256,512);
soeProtocol.pack_session_reply_packet(1008176227, 0, 2, 256, 512);
});

bench("Pack Ping", () => {
Expand Down Expand Up @@ -186,15 +187,25 @@ bench("Pack Data packet", () => {
});

bench("Pack Data DIRECT ACCESS", () => {
soeProtocol.pack_data_packet(new Uint8Array([2,1,1,0,0,0,1,1,3,0,0,0,115,111,101,0,0,0,0]),0);
soeProtocol.pack_data_packet(
new Uint8Array([
2, 1, 1, 0, 0, 0, 1, 1, 3, 0, 0, 0, 115, 111, 101, 0, 0, 0, 0,
]),
0,
);
});

bench("Pack Data Fragment packet", () => {
soeProtocol.pack_data(dataFragmentPacketToPack);
});

bench("Pack Data Fragment packet DIRECT ACCESS", () => {
soeProtocol.pack_fragment_data_packet(new Uint8Array([2,1,1,0,0,0,1,1,3,0,0,0,115,111,101,0,0,0,0]),0);
soeProtocol.pack_fragment_data_packet(
new Uint8Array([
2, 1, 1, 0, 0, 0, 1, 1, 3, 0, 0, 0, 115, 111, 101, 0, 0, 0, 0,
]),
0,
);
});

console.log("\n Pack tests with stringify \n");
Expand All @@ -210,7 +221,7 @@ const dataFragmentPacketToPackStringify = JSON.parse(dataFragmentPacketToPack);

bench("Pack Session Request", () => {
soeProtocol.pack_session_request(
JSON.stringify(sessionRequestToPackStringify)
JSON.stringify(sessionRequestToPackStringify),
);
});

Expand All @@ -222,7 +233,7 @@ bench("Pack Ping", () => {
});
bench("Pack Out of order packet", () => {
soeProtocol.pack_out_of_order(
JSON.stringify(outOfOrderPacketToPackStringify)
JSON.stringify(outOfOrderPacketToPackStringify),
);
});
bench("Pack Ack packet", () => {
Expand Down

0 comments on commit 75d8183

Please sign in to comment.