Skip to content

Instantly share code, notes, and snippets.

@oleh-zaporozhets
Last active March 9, 2020 15:41
Show Gist options
  • Save oleh-zaporozhets/279a2ff7af1f0da881a8a0aa5915b676 to your computer and use it in GitHub Desktop.
Save oleh-zaporozhets/279a2ff7af1f0da881a8a0aa5915b676 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const str = fs.readFileSync('./str.txt', 'utf8');
console.log('String length:', str.length);
console.log('---------');
function test() {
console.time('Split speed');
const res = str.split('').join(' ');
const used = process.memoryUsage().heapUsed / 1024 / 1024;
console.log(`Split uses approximately ${Math.round(used * 100) / 100} MB`);
console.timeEnd('Split speed');
console.log('---------');
}
for (let index = 0; index < 10; index++) {
test();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment