Last active
August 29, 2015 14:20
-
-
Save neale/5cb8e10fe81cf45b4df8 to your computer and use it in GitHub Desktop.
Two functions to find the longest possible variable length, which turns out the be the max memory allocation to a node process
This file contains hidden or 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
#!/usr/bin/env node | |
function name1(err) { | |
var name = ''; | |
var interation = 0; | |
for (var i = 0; i < 9007199254740992; ++i) { | |
delete global[name]; | |
name += 'x'; | |
global[name] = 42; | |
iteration = i; | |
//speed up the printing, console.log is a snail | |
if ((i%2) == 0) { | |
console.log(i); | |
} | |
if(err){ | |
console.log("max length of var name: ", i); | |
} | |
} | |
} | |
function name2(err) { | |
var name = ''; | |
var interation = 0; | |
//for max length of int | |
for (var i = 0; i < 9007199254740992; ++i) { | |
name += 'x'; | |
iteration = i; | |
if (err){ | |
console.log("max len of var name: ", i); | |
} | |
//print out the premature termination | |
} | |
console.log(eval(name)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment