Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Numbers (Shot of my browser)

  1. #11
    Join Date
    Mar 2011
    Location
    N 11 19' 0.0012 E 142 15' 0
    Posts
    1,524
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    Thanks guys

  2. #12
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    There is a way to do this, but it won't be as fast.

    Code:
    <script type="text/javascript">
    var count = function() {
      if (typeof i == "undefined") i = 0;
      if (i < 1000000) {
        i++;
        document.getElementById("whatever").innerHTML += i;
        setTimeout(function() { count(i); }, 0);
      }
    }
    window.onload = function() {
      var div = document.createElement("div");
      div.id = "whatever";
      document.body.appendChild(div);
      count();
    }
    </script>
    I didn't really test it, but I'm assuming that it works.

    EDIT: I did test it, it works.
    Last edited by mburt; 04-03-2012 at 10:29 PM.
    - Mike

  3. #13
    Join Date
    Mar 2011
    Location
    N 11 19' 0.0012 E 142 15' 0
    Posts
    1,524
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    But that would just print out one number wouldn't it? I'm trying to print out 100000000 numbers not the number 100000000.

  4. #14
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    No check it again, I edited it slightly, it prints out however many numbers you want. It's slower, but it won't crash your browser.
    - Mike

  5. #15
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    And I actually figured out a way to make this even faster:

    Code:
    <script type="text/javascript">
    var count = function() {
      if (typeof i == "undefined") i = 0;
      var interval = 100, max = 100;
      if (i < max) {
        for (var a = i; a < i+interval; a++) {
          document.getElementById("whatever").innerHTML += a;
        }
        i = i+interval;
        setTimeout(function() { count(i); }, interval);
      }
    }
    window.onload = function() {
      var div = document.createElement("div");
      div.id = "whatever";
      document.body.appendChild(div);
      count();
    }
    </script>
    keyboard, you can mess with those two variables to figure out where the maximum performance lies.
    Last edited by mburt; 04-03-2012 at 10:45 PM.
    - Mike

  6. The Following User Says Thank You to mburt For This Useful Post:

    keyboard (04-04-2012)

  7. #16
    Join Date
    Mar 2011
    Location
    N 11 19' 0.0012 E 142 15' 0
    Posts
    1,524
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    Michael, you complete legend

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
  •