Skip to content

Instantly share code, notes, and snippets.

@neale
Last active August 29, 2015 14:20
Show Gist options
  • Save neale/5cb8e10fe81cf45b4df8 to your computer and use it in GitHub Desktop.
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
#!/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