Results 1 to 22 of 22

Thread: How long does it take your computer to do this?

  1. #1
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default How long does it take your computer to do this?

    Was bored so create this:

    Lape

    Simba Code:
    var
      t, PH, n:integer;
    function GroupDigits(n: integer; token: String): String;
    var
      b: integer;
    begin
      Result := IntToStr(n);

      b := length(Result) + 1;
      if (b > 3) then
      repeat
        b := b - 3;
        if (b > 1) then
          insert(token, Result, b);
      until (b < 3);
    end;
    procedure MarkTime(var TimeMarker: Integer);
    begin
      TimeMarker := GetSystemTime;
    end;
    function TimeFromMark(TimeMarker: Integer): Integer;
    begin
      Result := GetSystemTime - TimeMarker;
    end;
    function RandString(chars:integer; upperCase:Boolean):string;
    var
      charArray: Array[0..1] of TStringArray;
      i:Integer;
    begin
      charArray[0] := ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9'];
      charArray[1] := ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9'];
      for i:=0 to chars do
      begin
        case upperCase of
          True:  result := result + charArray[Random(2)][Random(34)];
          False: result := result + charArray[0][Random(34)];
        end;
      end;
    end;
    begin
      n := 1000000;
      MarkTime(t);
      randString(n, False);
      Writeln('finished in ' + ToStr(TimeFromMark(t)) + ' ms');
      PH := Round(n * (3600.0 / (GetTimeRunning / 1000.0)));
      Writeln('Characters per hour ' + ToStr(Groupdigits(PH, ',')));
    end.

    Code:
    finished in 203 ms
    Characters per hour 1,905,692,230


    Java

    Characters per hour is messed up for some reason but whatever

    java Code:
    package random;
    import java.util.Random;
    public class randomString {
        static String Letters, randL;

        public static int random(int num) {
            Random Number = new Random();
            int r = Number.nextInt(num);
            return r;
        }
        public static String randChar(int times, boolean useCase) {
           
            String[][] chars = {
                    { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l",
                            "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w",
                            "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8",
                            "9" },
                    { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
                            "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W",
                            "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8",
                            "9" }, };
           
            randL = "";
            Letters = "";
            for (int x=0; x<times; x++) {
                if (useCase) {
                    Letters = randL + chars[random(2)][random(34)];
                } else {
                    Letters = randL +  chars[0][random(34)];
                }
            }
            return Letters;
        }

        public static void main(String args[]) {
            int n = 10000000;
            long startTime = System.currentTimeMillis();
            randChar(n, true);
            long endTime = System.currentTimeMillis();
            long duration = endTime - startTime;
            double PH = Math.round((n * (3600/(System.currentTimeMillis()/1000.0))));
            System.out.println("Finished in " + duration + " ms");
            System.out.println("Characters per hour " + PH);
        }

    }
    Code:
    Finished in 203 ms
    Characters per hour 3.0

    c++

    Thank to Le Jingle:
    c++ Code:
    #include <iostream>
    #include <stdlib.h>
    #include <string.h>
    #include <cstdio>
    #include <ctime>

    using namespace std;

    const int amt = 1000000000; // 1 Billion
    const char x[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
    string s = "";

    int main() {
        double duration;
        cout << "Testing String: " << &s << ", Elements: " << amt << endl;
        clock_t start;
        start = clock();
        for (int i = 0; i < amt; i++)
            s += x[rand() % 26];
        duration = (clock() - start) / (double) CLOCKS_PER_SEC;
        cout << "Time: " << duration << " seconds" << endl;
        cin.get();
        return 0;
    }

    Python

    Thanks to warpie:
    python Code:
    from random import randint
    from string import ascii_lowercase, digits, ascii_uppercase
    from time import time

    def intWithCommas(x):
        if type(x) not in [type(0), type(0L)]:
            raise TypeError("Parameter must be an integer.")
        if x < 0:
            return '-' + intWithCommas(-x)
        result = ''
        while x >= 1000:
            x, r = divmod(x, 1000)
            result = ",%03d%s" % (r, result)
        return "%d%s" % (x, result)

    def rand_string(times, allchars=False):
        if allchars: chars = ascii_lowercase + ascii_uppercase + digits
        else: chars = ascii_lowercase + digits
        size = len(chars)-1
        letters = []

        for x in range(times):
            letters.append(chars[randint(0,size)])

        return letters #"".join(letters)


    if __name__ == '__main__':
      n = 10000000
      t = time()
      rand_string(n, False)

      print 'finished in', str((time() - t)*1000) ,'ms'
      PH = int(round(n * (3600.0 / (time()-t))))
      print 'Characters per hour', intWithCommas(PH)

  2. #2
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    Am i doing it right:

    Simba Code:
    Extensions Updater Enabled!
    Loading extension C:\Simba\Extensions\srl.sex
    Extension Enabled
    SRL Updater Enabled!
    Plugins Updater Enabled!
    SPS Updater Enabled!
    MSI Updater Enabled!
    Simba news:

        The forums will be up again soon. For more information; see
        http://blog.wizzup.org/blog/villavu-breach

        Small update; I (Wizzup?) will be getting some more free time soon; expect
        the release of 994 very soon, followed by the first alpha of Simba 1.0!

        As always, see you on our homepage; http://villavu.com


    Thank you for using Simba,
    Hakuna Matata.

    Compiled successfully in 437 ms.
    finished in 1154 ms
    Characters per hour -2,032,239,452
    Successfully executed.
    wat

  3. #3
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Sin View Post
    Am i doing it right:

    Simba Code:
    Extensions Updater Enabled!
    Loading extension C:\Simba\Extensions\srl.sex
    Extension Enabled
    SRL Updater Enabled!
    Plugins Updater Enabled!
    SPS Updater Enabled!
    MSI Updater Enabled!
    Simba news:

        The forums will be up again soon. For more information; see
        http://blog.wizzup.org/blog/villavu-breach

        Small update; I (Wizzup?) will be getting some more free time soon; expect
        the release of 994 very soon, followed by the first alpha of Simba 1.0!

        As always, see you on our homepage; http://villavu.com


    Thank you for using Simba,
    Hakuna Matata.

    Compiled successfully in 437 ms.
    finished in 1154 ms
    Characters per hour -2,032,239,452
    Successfully executed.
    wat
    Edited it to 500,000 lol my bad

  4. #4
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    Simba Code:
    Compiled successfully in 437 ms.
    finished in 22261 ms
    Characters per hour 793,021,412

    Your i7 > my 6core

  5. #5
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Sin View Post
    Simba Code:
    Compiled successfully in 437 ms.
    finished in 22261 ms
    Characters per hour 793,021,412

    Your i7 > my 6core
    Bahaha. Going for 2.5m let's see how long it takes

  6. #6
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    finished in 15475 ms
    Characters per hour 1,139,024,236
    Successfully executed.

  7. #7
    Join Date
    Dec 2011
    Location
    United States
    Posts
    960
    Mentioned
    21 Post(s)
    Quoted
    504 Post(s)

    Default

    Lape
    Code:
    finished in 203 ms
    Characters per hour 1,905,692,230
    Last edited by Wetish; 07-21-2013 at 04:47 AM.

  8. #8
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    2.5m chars (pascalscript):

    Code:
    finished in 864313 ms
    Characters per hour 41,632,792
    10m chars (lape):

    Code:
    finished in 2328 ms
    Characters per hour 1,695,900,056
    100m chars (lape):

    Code:
    finished in 45140 ms
    Characters per hour -,642,388,397

  9. #9
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    For 100m
    Code:
    finished in 38125 ms
    Characters per hour 821,830,114
    Successfully executed.
    Potential to push closer to < 10 seconds, but not worth the effort +

  10. #10
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Le Jingle View Post
    For 100m
    Code:
    finished in 38125 ms
    Characters per hour 821,830,114
    Successfully executed.
    Potential to push closer to < 10 seconds, but not worth the effort +
    1,000,000,000:

    Used constant 17-18% CPU and slow rose from 18 mb of ram up to 950 MB

    Got an out of memory error lol I guess simba can't use > 1 GB of RAM?

  11. #11
    Join Date
    Jul 2012
    Posts
    437
    Mentioned
    10 Post(s)
    Quoted
    165 Post(s)

    Default

    500,000
    ps
    Code:
    Compiled successfully in 47 ms.
    finished in 132641 ms
    Characters per hour 135,704,646
    Successfully executed.
    lape
    Code:
    Compiled successfully in 437 ms.
    finished in 875 ms
    Characters per hour -1,250,117,379
    Successfully executed.

  12. #12
    Join Date
    Mar 2007
    Posts
    5,125
    Mentioned
    275 Post(s)
    Quoted
    901 Post(s)

    Default

    Code:
    finished in 187 ms
    Characters per hour -1,875,727,576
    Successfully executed.

    Forum account issues? Please send me a PM

  13. #13
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    From your one using Lape (I had to change from 32-bit integer to 64-bit integer as it just kept overflowing):
    Code:
    Compiled successfully in 202 ms.
    finished in 16 ms
    Characters per hour 16,513,761,467,889,908
    Successfully executed.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  14. #14
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Compiled successfully in 202 ms.
    finished in 265 ms
    Characters per hour 7,453,416,149
    Successfully executed.

    With bots running. That's in Lape though on my laptop. P.S. takes so much longer!
    I am Ggzz..
    Hackintosher

  15. #15
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    Compiled successfully in 202 ms.
    finished in 265 ms
    Characters per hour 7,453,416,149
    Successfully executed.

    With bots running. That's in Lape though on my laptop. P.S. takes so much longer!
    I'm about to test it in java think it will be even faster? :s I have no idea

    EDIT: slow in java unless my code is just bad (probably that)

    Java and lape same speed for me gotta do some additional testing

    100m chars lape:

    Code:
    finished in 46062 ms
    Characters per hour -,800,930,070
    100m chars Java:

    Code:
    Finished in 8953 ms
    Characters per hour 262.0
    1b chars java:

    Code:
    Finished in 88538 ms
    Characters per hour 2619.0

    Lape is pretty dang good but it's no match for Java

  16. #16
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Quote Originally Posted by Officer Barbrady View Post
    I'm about to test it in java think it will be even faster? :s I have no idea

    EDIT: slow in java unless my code is just bad (probably that)

    Java and lape same speed for me gotta do some additional testing

    100m chars lape:

    Code:
    finished in 46062 ms
    Characters per hour -,800,930,070
    100m chars Java:

    Code:
    Finished in 8953 ms
    Characters per hour 262.0
    1b chars java:

    Code:
    Finished in 88538 ms
    Characters per hour 2619.0

    Lape is pretty dang good but it's no match for Java
    Your Java version is incorrect. You don't seem to be extending you char-list (letters).

    Code:
            randL = ""; //I am ALWAYS empty.
            Letters = "";
            for (int x=0; x<times; x++) {
                if (useCase) {
                    Letters = randL + chars[random(2)][random(34)];
                } else {
                    Letters = randL +  chars[0][random(34)];
                }
            }
            return Letters;
    --> Note: Letters = randL + chars[0][random(34)];
    Pseudo answer to that: Letters += chars[0][random(34)]; --- And drop randL which is always empty.

    But that would use a whole lot of memory - If char = 1 byte in Java: Then 1B chars close to 1GB mem.


    On my computer in Python (PyPy) with Java-version (Where I do not extend "Letters"):
    Code:
    Iterations = 1,000,000,000
    finished in 86046.9999313 ms
    Characters per hour 41,837,600,415
    By extending Letters with a new char:
    Code:
    Iterations = 10,000,000
    finished in 2218.99986267 ms
    Characters per hour 16,223,525,114
    Python-code (PyPy-optimal) (based on Lape-code):
    Code:
    from random import randint
    from string import ascii_lowercase, digits, ascii_uppercase
    from time import time
    
    def intWithCommas(x):
        if type(x) not in [type(0), type(0L)]:
            raise TypeError("Parameter must be an integer.")
        if x < 0:
            return '-' + intWithCommas(-x)
        result = ''
        while x >= 1000:
            x, r = divmod(x, 1000)
            result = ",%03d%s" % (r, result)
        return "%d%s" % (x, result)
    
    def rand_string(times, allchars=False): 
        if allchars: chars = ascii_lowercase + ascii_uppercase + digits
        else: chars = ascii_lowercase + digits
        size = len(chars)-1
        letters = []
    
        for x in range(times):
            letters.append(chars[randint(0,size)])
    
        return letters #"".join(letters)
    
    
    if __name__ == '__main__':
      n = 10000000
      t = time()
      rand_string(n, False)
    
      print 'finished in', str((time() - t)*1000) ,'ms'
      PH = int(round(n * (3600.0 / (time()-t))))
      print 'Characters per hour', intWithCommas(PH)
    Edit: Constant 12% CPU-usage: (1 of 8 cores).

  17. #17
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by warpie View Post
    Your Java version is incorrect. You don't seem to be extending you char-list (letters).

    Code:
            randL = ""; //I am ALWAYS empty.
            Letters = "";
            for (int x=0; x<times; x++) {
                if (useCase) {
                    Letters = randL + chars[random(2)][random(34)];
                } else {
                    Letters = randL +  chars[0][random(34)];
                }
            }
            return Letters;
    --> Note: Letters = randL + chars[0][random(34)];
    Pseudo answer to that: Letters += chars[0][random(34)]; --- And drop randL which is always empty.

    But that would use a whole lot of memory - If char = 1 byte in java (which I doubt - thinks it more). Then 1B chars close to 1GB mem.
    Meh I'm not very good at java

  18. #18
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Yeah, now you at least know why you Java version was so fast..
    By appending, you will see probably the same time as used by Lape, or PyPy. It's the appending a new char to `letters` that really takes time.

  19. #19
    Join Date
    Feb 2007
    Location
    Colorado, USA
    Posts
    3,716
    Mentioned
    51 Post(s)
    Quoted
    624 Post(s)

    Default

    Compiled successfully in 109 ms.
    finished in 140 ms
    Characters per hour 1,572,929,437
    Successfully executed.

    I have awesome single threaded power (lape)
    The only true authority stems from knowledge, not from position.

    You can contact me via matrix protocol: @grats:grats.win or you can email me at the same domain, any user/email address.

  20. #20
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by warpie View Post
    Yeah, now you at least know why you Java version was so fast..
    By appending, you will see probably the same time as used by Lape, or PyPy. It's the appending a new char to `letters` that really takes time.
    Added your python version now we just need a c++

    @warpie Can I get a test output? I'm not good at Python stuff (cba to trouble shoot my error)

  21. #21
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    Tested 1 Billion with c++ in the cmd, results with 10-15% CPU, also hit up to about 950 mb in RAM:
    Code:
    Testing String: 0x40c030, Elements: 1000000000
    Time: 12.485 seconds
    edit: my source code below (critique's accepted as I'm nowhere near decent in c++)
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <string.h>
    #include <cstdio>
    #include <ctime>
    
    using namespace std;
    
    const int amt = 1000000000; // 1 Billion
    const char x[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
    string s = "";
    
    int main() {
    	double duration;
    	cout << "Testing String: " << &s << ", Elements: " << amt << endl;
    	clock_t start;
    	start = clock();
    	for (int i = 0; i < amt; i++)
    		s += x[rand() % 26];
    	duration = (clock() - start) / (double) CLOCKS_PER_SEC;
    	cout << "Time: " << duration << " seconds" << endl;
    	cin.get();
    	return 0;
    }
    Last edited by Le Jingle; 07-23-2013 at 06:39 AM.

  22. #22
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Le Jingle View Post
    Tested 1 Billion with c++ in the cmd, results with 10-15% CPU, also hit up to about 950 mb in RAM:
    Code:
    Testing String: 0x40c030, Elements: 1000000000
    Time: 12.485 seconds
    edit: my source code below (critique's accepted as I'm nowhere near decent in c++)
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <string.h>
    #include <cstdio>
    #include <ctime>
    
    using namespace std;
    
    const int amt = 1000000000; // 1 Billion
    const char x[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
    string s = "";
    
    int main() {
    	double duration;
    	cout << "Testing String: " << &s << ", Elements: " << amt << endl;
    	clock_t start;
    	start = clock();
    	for (int i = 0; i < amt; i++)
    		s += x[rand() % 26];
    	duration = (clock() - start) / (double) CLOCKS_PER_SEC;
    	cout << "Time: " << duration << " seconds" << endl;
    	cin.get();
    	return 0;
    }
    Added to OP thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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