Skip to content

Instantly share code, notes, and snippets.

@dmlap
Last active August 29, 2015 13:58
Show Gist options
  • Select an option

  • Save dmlap/10289063 to your computer and use it in GitHub Desktop.

Select an option

Save dmlap/10289063 to your computer and use it in GitHub Desktop.
Results from performance testing methods of converting a UInt8Array into a base64-encoded string in Firefox 28/OS X.

Control:

Bytes Appends Elapsed Milliseconds
1000 10000 2898
1000 10000 2898
1000 10000 2899

Converting the Uint8Array to a "binary string" with String.fromCharCode and then using btoa:

Bytes Appends Elapsed Milliseconds
1000 10000 3458
1000 10000 3415
1000 10000 3423

Turning the Uint8Array into a regular array with slice, mapping the result with String.fromCharCode, and then joining with the empty string:

Bytes Appends Elapsed Milliseconds
1000 10000 5955
1000 10000 6202
1000 10000 5681

Creating a blob and using FileReader's readAsDataURL to base64 encode it:

Bytes Appends Elapsed Milliseconds
1000 10000 4379
1000 10000 4585
1000 10000 4649
1000 10000 4534
1000 10000 4722

Performing an "interesting" byte-by-byte transformation in a single pass. This isn't actual base64 encoding but it should be roughly equivalent:

Bytes Appends Elapsed Milliseconds
1000 10000 2298
1000 10000 2240
1000 10000 2303

Pass a constant, 1000 length string of As into the SWF:

Bytes Appends Elapsed Milliseconds
1000 10000 2339
1000 10000 2375
1000 10000 2380
1000 10000 2582
1000 10000 2487

Varying number of appends:

Bytes Appends Elapsed Milliseconds
1000 10000 2543
1000 10000 2546
1000 10000 2624
10000 1000 623
10000 1000 609
10000 1000 623
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment