SRL Archive - NOTA

How long does it take your computer to do this?


rj

2013-07-20 22:49:08

Was bored so create this:

[spoiler=Lape]

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.

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

[/spoiler]

[spoiler=Java]
Characters per hour is messed up for some reason but whatever

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);
}

}
Finished in 203 ms
Characters per hour 3.0
[/spoiler]
[spoiler=c++]
Thank to Le Jingle:
#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;
}
[/spoiler]
[Spoiler=Python]
Thanks to warpie:
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)
[/spoiler]

Sin

2013-07-20 22:50:37

Am i doing it right:

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

rj

2013-07-20 22:52:44

From: Sin
Am i doing it right:

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

Sin

2013-07-20 22:54:18

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

Your i7 > my 6core

rj

2013-07-20 22:57:52

From: Sin
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

NKN

2013-07-20 22:57:53

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

Wetish

2013-07-20 23:20:52

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

rj

2013-07-20 23:22:31

2.5m chars (pascalscript):

finished in 864313 ms
Characters per hour 41,632,792

10m chars (lape):

finished in 2328 ms
Characters per hour 1,695,900,056

100m chars (lape):

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

Le Jingle

2013-07-20 23:41:02

For 100m

finished in 38125 ms
Characters per hour 821,830,114
Successfully executed.

Potential to push closer to < 10 seconds, but not worth the effort :p + :)

rj

2013-07-20 23:44:10

From: Le Jingle
For 100m

finished in 38125 ms
Characters per hour 821,830,114
Successfully executed.

Potential to push closer to < 10 seconds, but not worth the effort :p + :)


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?

tealc

2013-07-21 00:44:26

500,000
ps

Compiled successfully in 47 ms.
finished in 132641 ms
Characters per hour 135,704,646
Successfully executed.

lape

Compiled successfully in 437 ms.
finished in 875 ms
Characters per hour -1,250,117,379
Successfully executed.

Justin

2013-07-21 05:49:46


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

Daniel

2013-07-21 09:26:52

From your one using Lape (I had to change from 32-bit integer to 64-bit integer as it just kept overflowing):
Compiled successfully in 202 ms.
finished in 16 ms
Characters per hour 16,513,761,467,889,908
Successfully executed.

Brandon

2013-07-21 15:40:01

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!

rj

2013-07-21 18:21:31

From: Brandon
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:

finished in 46062 ms
Characters per hour -,800,930,070

100m chars Java:

Finished in 8953 ms
Characters per hour 262.0

1b chars java:

Finished in 88538 ms
Characters per hour 2619.0


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

slacky

2013-07-21 21:21:22

From: Officer Barbrady
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:

finished in 46062 ms
Characters per hour -,800,930,070

100m chars Java:

Finished in 8953 ms
Characters per hour 262.0

1b chars java:

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).


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"):

Iterations = 1,000,000,000
finished in 86046.9999313 ms
Characters per hour 41,837,600,415

By extending Letters with a new char:

Iterations = 10,000,000
finished in 2218.99986267 ms
Characters per hour 16,223,525,114

Python-code (PyPy-optimal) (based on Lape-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).

rj

2013-07-21 21:22:51

From: warpie
Your Java version is incorrect. You don't seem to be extending you char-list (letters).


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

slacky

2013-07-21 21:56:56

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.

grats

2013-07-22 08:19:11

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)

rj

2013-07-22 10:44:59

From: warpie
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)

Le Jingle

2013-07-23 02:32:50

Tested 1 Billion with c++ in the cmd, results with 10-15% CPU, also hit up to about 950 mb in RAM:

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++)

#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;
}

rj

2013-07-23 17:39:29

From: Le Jingle
Tested 1 Billion with c++ in the cmd, results with 10-15% CPU, also hit up to about 950 mb in RAM:

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++)

#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