Code:<script type="text/javascript"> for(var i=0; i<10000000; i++) { var randomNumber=Math.floor(Math.random()*100) document.write(randomNumber + " "); } </script>
Code:<script type="text/javascript"> for(var i=0; i<10000000; i++) { var randomNumber=Math.floor(Math.random()*100) document.write(randomNumber + " "); } </script>
Last edited by keyboard; 04-04-2012 at 08:45 AM.
This is what recursive functions are useful for. On the other hand, that would be a great way to guarantee crashing your browser. (Did 10000000 not crash it?)
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Yep, sometimes it crashed and sometimes IE stopped it because the script took to long. I'm not actually sure how many of the values it printed.
Ummmmm no should I have?
EDIT -
That time it managed to print out 307494 before I had to recover the webpage
Happy Traq?![]()
Last edited by keyboard; 04-03-2012 at 01:03 AM.
Okay -
but know it'll only print around 25000 before IE9 says it's running for to long and stops it.Code:<html> <head> </head> <body> <div id="display"></div> <input type="button" onclick="count()" /> <script type="text/javascript"> for(var i=0; i<100000000; i++) { var randomNumber=Math.floor(Math.random()*100) var getID = document.getElementById('display'); getID.innerHTML = getID.innerHTML + randomNumber + " "; } function count() { var getID = document.getElementById('display'); var numNum = getID.innerHTML.split(' ').length; alert(numNum - 1); } </script> </body> </html>
Anyone got a suggestion to make it run faster or print more values?
I'm only fiddling with this for fun so mods, please don't move this thread to a different forum.
Nope. That's the memory limit for your browser. You can close all other applications, buy more RAM, and potentially switch to a more efficient browser (not sure which is best), but in the end it'll still have a maximum amount.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Though, Daniel, correct me if I'm wrong, I think you can reduce the amount of memory used by opening up your variables. For example, something like the following:
(only defining getID once, never defining randomNumber, using appendChild and createTextNode because that way the browser doesn't need to render anything, therefore faster).Code:for(var i = 0, getID = document.getElementById('display'); i < 100000000; i++){ getID.appendChild(document.createTextNode(Math.floor(Math.random()*100) + " ")); }
@keyboard
I'm just as scared to run this as I am:
Code:while(1){ document.write(1); }
You can optimize it, but it's still going to max out. I also expect that it will get you smaller and smaller improvements because holding all of that in memory (just the text of the page even) will eventually be too much for the computer and compound on itself.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Bookmarks