Created
May 27, 2021 13:45
-
-
Save fabiospampinato/014d15872e2129774ae23783bd377ad2 to your computer and use it in GitHub Desktop.
charCodeAt vs TextEncoder benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require ( 'fs' ); | |
const content = fs.readFileSync ( 'War and Peace.md', 'utf-8' ); | |
const charCodesAt = new Array ( content.length ); | |
console.time('charCodeAt'); | |
for ( let i = 0, l = content.length; i < l; i++ ) { | |
charCodesAt[i] = content.charCodeAt ( i ); | |
} | |
console.timeEnd('charCodeAt'); | |
const encoder = new TextEncoder (); | |
console.time('TextEncoder'); | |
encoder.encode ( content ) | |
console.timeEnd('TextEncoder'); | |
console.log ( content.length ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment