deno.land / x / msgpack_javascript@v3.0.0-beta2 / benchmark / encode-string.ts
12345678910111213141516171819202122232425262728293031323334/* eslint-disable no-console */import { utf8EncodeJs, utf8Count, utf8EncodeTE } from "../src/utils/utf8";
// @ts-ignoreimport Benchmark from "benchmark";
for (const baseStr of ["A", "あ", "🌏"]) { const dataSet = [10, 30, 50, 100].map((n) => { return baseStr.repeat(n); });
for (const str of dataSet) { const byteLength = utf8Count(str); const buffer = new Uint8Array(byteLength);
console.log(`\n## string "${baseStr}" (strLength=${str.length}, byteLength=${byteLength})\n`);
const suite = new Benchmark.Suite();
suite.add("utf8EncodeJs", () => { utf8EncodeJs(str, buffer, 0); });
suite.add("utf8DecodeTE", () => { utf8EncodeTE(str, buffer, 0); }); suite.on("cycle", (event: any) => { console.log(String(event.target)); });
suite.run(); }}
Version Info