|
8 | 8 |
|
9 | 9 | <body> |
10 | 10 | <script type="module"> |
11 | | - import init, { encode, decode } from "./pkg/web/base64_simd_wasm_vn.js"; |
| 11 | + import { Bench } from 'https://cdn.jsdelivr.net/npm/tinybench@6.0.0/dist/index.min.js' |
| 12 | + import init, { encode, decode, encodeUrlNoPad, decodeUrlNoPad } from "./pkg/web/base64_simd_wasm_vn.js"; |
12 | 13 |
|
13 | | - const encoder = new TextEncoder(); |
14 | | - const decoder = new TextDecoder(); |
| 14 | + const dataTXT = ` |
| 15 | + To find information about a command, on the A-Z button menu at the top of this page, click the letter that the command starts with, and then click the command name. |
| 16 | + In addition to the tools installed with Windows XP, there are over 40 support tools included on the Windows XP CD. You can use these tools to diagnose and resolve computer problems. |
| 17 | + For more information about these support tools, see Windows Support Tools For information about installing support tools, see Install Windows Support Tools |
| 18 | + For more information about changes to the functionality of MS-DOS commands, new command-line tools, command shell functionality, configuring the command prompt, |
| 19 | + and automating commmand-line tasks, see Command-line reference |
| 20 | + Some command-line tools require the user to have administrator-level privileges on source and/or target computers. |
| 21 | + Command-line tools must be run at the prompt of the Cmd.exe command interpreter. To open Command Prompt, click Start, click Run, type cmd, |
| 22 | + and then click OK. To view help at the command-line, at the command prompt, type the following |
| 23 | + We're no longer updating this content regularly. Check the Microsoft Product Lifecycle for information about how this product, service, technology, or API is supported. |
| 24 | + `; |
| 25 | + const dataBytes = new TextEncoder().encode(dataTXT); |
15 | 26 |
|
16 | | - init().then(() => { |
17 | | - const data = "SIMD-accelerated base64 encoding and decoding" |
| 27 | + // --- Init WASM once --- |
| 28 | + await init() |
18 | 29 |
|
19 | | - const encoded = encode(encoder.encode(data)); |
20 | | - const decoded = decode(encoded); |
| 30 | + // Tests |
| 31 | + const encoded = encode(dataBytes); |
| 32 | + const decoded = decode(encoded); |
21 | 33 |
|
22 | | - console.log("data: ", data); |
23 | | - console.log("encode: ", encoded); |
24 | | - console.log("decode: ", decoded); |
| 34 | + console.log("data: ", dataTXT); |
| 35 | + console.log("encode-simd: ", encoded); |
| 36 | + console.log("decode-simd: ", decoded); |
| 37 | + console.log("encode-web: ", btoa(dataTXT)); |
| 38 | + console.log("decode-web: ", atob(encoded)); |
25 | 39 |
|
26 | | - const text = decoder.decode(decoded) |
| 40 | + console.assert(new TextDecoder().decode(decoded) === dataTXT, "Base64 decode failed"); |
27 | 41 |
|
28 | | - console.log("text: ", text); |
| 42 | + const encodedUrlNoPad = encodeUrlNoPad(dataBytes); |
| 43 | + const decodedUrlNoPad = decodeUrlNoPad(encodedUrlNoPad); |
| 44 | + |
| 45 | + // --- Benchmark --- |
| 46 | + const bench = new Bench({ |
| 47 | + name: 'base64 benchmark', |
| 48 | + time: 200, |
| 49 | + }) |
| 50 | + |
| 51 | + bench |
| 52 | + // STANDARD BASE64 |
| 53 | + .add('base64-simd-wasm-vn encode', () => encode(dataBytes)) |
| 54 | + .add('browser btoa encode', () => btoa(dataTXT)) |
| 55 | + .add('base64-simd-wasm-vn decode', () => decode(encoded)) |
| 56 | + .add('browser atob decode', () => atob(encoded)) |
| 57 | + // BASE64 URL (NO PAD) |
| 58 | + .add('base64-simd-wasm-vn encodeUrlNoPad', () => encodeUrlNoPad(dataBytes)) |
| 59 | + .add('base64-simd-wasm-vn decodeUrlNoPad', () => decodeUrlNoPad(encodedUrlNoPad)); |
| 60 | + |
| 61 | + await bench.run() |
| 62 | + |
| 63 | + console.log(bench.name) |
| 64 | + console.table(bench.table()) |
29 | 65 |
|
30 | | - if (data === text) { |
31 | | - console.log('Ok !'); |
32 | | - } |
33 | | - }); |
34 | 66 | </script> |
35 | 67 | </body> |
36 | 68 |
|
|
0 commit comments