Advanced Search

Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Numbers (Shot of my browser)

  1. #1
    Join Date
    Mar 2011
    Location
    N 11° 19' 0.0012 E 142° 15' 0
    Posts
    1,424
    Thanks
    37
    Thanked 84 Times in 83 Posts
    Blog Entries
    3

    Default Numbers (Shot of my browser)



    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 keyboard1333; 04-04-2012 at 08:45 AM.
    keebs - keyboard1333 [at] gmail [dot] com
    Anime Views Forums

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,165
    Thanks
    62
    Thanked 446 Times in 435 Posts
    Blog Entries
    7

    Default

    uhh.... "congrats"?

    Adrian ~ facebook | gist/github

    ['66.215.156.37','208.75.149.97'] // ip,ip array!
    "Take that sticker *off* your hat; you look stupid" --Wil Wheaton

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    11,830
    Thanks
    231
    Thanked 659 Times in 647 Posts

    Default

    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>| Deutsch | italiano | español | português | català | un peu de français | Ninasoma Kiswahili | 日本語の学生でした。| درست العربية

  4. #4
    Join Date
    Mar 2011
    Location
    N 11° 19' 0.0012 E 142° 15' 0
    Posts
    1,424
    Thanks
    37
    Thanked 84 Times in 83 Posts
    Blog Entries
    3

    Default

    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.
    keebs - keyboard1333 [at] gmail [dot] com
    Anime Views Forums

  5. #5
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,165
    Thanks
    62
    Thanked 446 Times in 435 Posts
    Blog Entries
    7

    Default

    Quote Originally Posted by keyboard1333 View Post
    ... I'm not actually sure how many of the values it printed.
    what, you didn't COUNT THEM !?!?!
    Adrian ~ facebook | gist/github

    ['66.215.156.37','208.75.149.97'] // ip,ip array!
    "Take that sticker *off* your hat; you look stupid" --Wil Wheaton

  6. #6
    Join Date
    Mar 2011
    Location
    N 11° 19' 0.0012 E 142° 15' 0
    Posts
    1,424
    Thanks
    37
    Thanked 84 Times in 83 Posts
    Blog Entries
    3

    Default

    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 keyboard1333; 04-03-2012 at 01:03 AM.
    keebs - keyboard1333 [at] gmail [dot] com
    Anime Views Forums

  7. #7
    Join Date
    Mar 2011
    Location
    N 11° 19' 0.0012 E 142° 15' 0
    Posts
    1,424
    Thanks
    37
    Thanked 84 Times in 83 Posts
    Blog Entries
    3

    Default

    Okay -

    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>
    but know it'll only print around 25000 before IE9 says it's running for to long and stops it.

    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.
    keebs - keyboard1333 [at] gmail [dot] com
    Anime Views Forums

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    11,830
    Thanks
    231
    Thanked 659 Times in 647 Posts

    Default

    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>| Deutsch | italiano | español | português | català | un peu de français | Ninasoma Kiswahili | 日本語の学生でした。| درست العربية

  9. #9
    Join Date
    Jan 2008
    Posts
    4,103
    Thanks
    18
    Thanked 615 Times in 611 Posts
    Blog Entries
    5

    Default

    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:
    Code:
    for(var i = 0, getID = document.getElementById('display'); i < 100000000; i++){
    	getID.appendChild(document.createTextNode(Math.floor(Math.random()*100) + " "));
    }​
    (only defining getID once, never defining randomNumber, using appendChild and createTextNode because that way the browser doesn't need to render anything, therefore faster).

    @keyboard
    I'm just as scared to run this as I am:
    Code:
    while(1){
    document.write(1);
    }

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    11,830
    Thanks
    231
    Thanked 659 Times in 647 Posts

    Default

    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>| Deutsch | italiano | español | português | català | un peu de français | Ninasoma Kiswahili | 日本語の学生でした。| درست العربية

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •