Browse Source

Add string concat and compare perf tests

pull/156/head
Sami Vaarala 10 years ago
parent
commit
af20e6e0ea
  1. 23
      perf-testcases/test-string-array-concat.js
  2. 13
      perf-testcases/test-string-array-concat.lua
  3. 13
      perf-testcases/test-string-array-concat.pl
  4. 9
      perf-testcases/test-string-array-concat.py
  5. 15
      perf-testcases/test-string-array-concat.rb
  6. 68
      perf-testcases/test-string-compare.js
  7. 59
      perf-testcases/test-string-compare.lua
  8. 67
      perf-testcases/test-string-compare.pl
  9. 54
      perf-testcases/test-string-compare.py
  10. 64
      perf-testcases/test-string-compare.rb
  11. 24
      perf-testcases/test-string-intern-match.js
  12. 29
      perf-testcases/test-string-intern-miss.js
  13. 23
      perf-testcases/test-string-plain-concat.js
  14. 13
      perf-testcases/test-string-plain-concat.lua
  15. 14
      perf-testcases/test-string-plain-concat.pl
  16. 8
      perf-testcases/test-string-plain-concat.py
  17. 16
      perf-testcases/test-string-plain-concat.rb

23
perf-testcases/test-string-array-concat.js

@ -0,0 +1,23 @@
/*
* Build string with plain concat. Causes O(n^2) behavior because every
* intermediate step is string interned.
*/
function test() {
var i, j;
var t;
for (i = 0; i < 5e3; i++) {
t = [];
for (j = 0; j < 1e4; j++) {
t[j] = 'x';
}
t = t.join('');
}
}
try {
test();
} catch (e) {
print(e.stack || e);
}

13
perf-testcases/test-string-array-concat.lua

@ -0,0 +1,13 @@
function test()
local t
for i=1,5e3 do
t = {}
for j=1,1e4 do
t[j] = 'x'
end
t = table.concat(t)
end
end
test()

13
perf-testcases/test-string-array-concat.pl

@ -0,0 +1,13 @@
sub test {
my $i, $j, @t, $ign;
for ($i = 0; $i < 5e3; $i++) {
@t = ();
for ($j = 0; $j < 1e4; $j++) {
$t[$j] = 'x';
}
$ign = join('', @t);
}
}
test();

9
perf-testcases/test-string-array-concat.py

@ -0,0 +1,9 @@
def test():
for i in xrange(int(5e3)):
t = []
for j in xrange(int(1e4)):
#t[j] = 'x'
t.append('x')
t = ''.join(t)
test()

15
perf-testcases/test-string-array-concat.rb

@ -0,0 +1,15 @@
def test()
i = 0
while i < 5e3 do
t = []
j = 0
while j < 1e4 do
t[j] = 'x'
j += 1
end
t = t.join()
i += 1
end
end
test()

68
perf-testcases/test-string-compare.js

@ -0,0 +1,68 @@
/*
* Test string comparison. Interned strings compare by pointer so there's
* not much going on here.
*/
function test() {
var a, b, c, d, e, f, g;
var i;
function mk(n) {
var res = [];
for (var i = 0; i < n; i++) { res[i] = 'x'; }
res = res.join('');
print(res.length);
return res;
}
a = mk(0);
b = mk(1);
c = mk(16);
d = mk(256);
e = mk(4096);
f = mk(65536);
g = mk(1048576);
for (i = 0; i < 1e7; i++) {
void (a == a);
void (a == b);
void (a == c);
void (a == d);
void (a == e);
void (a == f);
void (a == g);
void (b == b);
void (b == c);
void (b == d);
void (b == e);
void (b == f);
void (b == g);
void (c == c);
void (c == d);
void (c == e);
void (c == f);
void (c == g);
void (d == d);
void (d == e);
void (d == f);
void (d == g);
void (e == e);
void (e == f);
void (e == g);
void (f == f);
void (f == g);
void (g == g);
}
}
try {
test();
} catch (e) {
print(e.stack || e);
}

59
perf-testcases/test-string-compare.lua

@ -0,0 +1,59 @@
function test()
local a, b, c, d, e, f, g
local ign
local function mk(n)
local res = {}
for i=1,n do table.insert(res, 'x') end
res = table.concat(res)
print(#res)
return res
end
a = mk(0)
b = mk(1)
c = mk(16)
d = mk(256)
e = mk(4096)
f = mk(65536)
g = mk(1048576)
for i=1,1e7 do
ign = (a == a);
ign = (a == b);
ign = (a == c);
ign = (a == d);
ign = (a == e);
ign = (a == f);
ign = (a == g);
ign = (b == b);
ign = (b == c);
ign = (b == d);
ign = (b == e);
ign = (b == f);
ign = (b == g);
ign = (c == c);
ign = (c == d);
ign = (c == e);
ign = (c == f);
ign = (c == g);
ign = (d == d);
ign = (d == e);
ign = (d == f);
ign = (d == g);
ign = (e == e);
ign = (e == f);
ign = (e == g);
ign = (f == f);
ign = (f == g);
ign = (g == g);
end
end
test()

67
perf-testcases/test-string-compare.pl

@ -0,0 +1,67 @@
sub mk {
my $n = shift;
my @res = ();
my $i;
my $tmp;
for ($i = 0; $i < $n; $i++) {
$res[$i] = 'x';
}
$tmp = join('', @res);
print(length $tmp);
print("\n");
return $tmp;
}
sub test {
my $a, $b, $c, $d, $e, $f, $g;
my $i, $ign;
$a = mk(0);
$b = mk(1);
$c = mk(16);
$d = mk(256);
$e = mk(4096);
$f = mk(65536);
$g = mk(1048576);
for ($i = 0; $i < 1e7; $i++) {
$ign = ($a == $a);
$ign = ($a == $b);
$ign = ($a == $c);
$ign = ($a == $d);
$ign = ($a == $e);
$ign = ($a == $f);
$ign = ($a == $g);
$ign = ($b == $b);
$ign = ($b == $c);
$ign = ($b == $d);
$ign = ($b == $e);
$ign = ($b == $f);
$ign = ($b == $g);
$ign = ($c == $c);
$ign = ($c == $d);
$ign = ($c == $e);
$ign = ($c == $f);
$ign = ($c == $g);
$ign = ($d == $d);
$ign = ($d == $e);
$ign = ($d == $f);
$ign = ($d == $g);
$ign = ($e == $e);
$ign = ($e == $f);
$ign = ($e == $g);
$ign = ($f == $f);
$ign = ($f == $g);
$ign = ($g == $g);
}
}
test();

54
perf-testcases/test-string-compare.py

@ -0,0 +1,54 @@
def test():
def mk(n):
res = []
for i in xrange(n):
res.append('x')
res = ''.join(res)
print(len(res))
return res
a = mk(0)
b = mk(1)
c = mk(16)
d = mk(256)
e = mk(4096)
f = mk(65536)
g = mk(1048576)
for i in xrange(int(1e7)):
ign = (a == a)
ign = (a == b)
ign = (a == c)
ign = (a == d)
ign = (a == e)
ign = (a == f)
ign = (a == g)
ign = (b == b)
ign = (b == c)
ign = (b == d)
ign = (b == e)
ign = (b == f)
ign = (b == g)
ign = (c == c)
ign = (c == d)
ign = (c == e)
ign = (c == f)
ign = (c == g)
ign = (d == d)
ign = (d == e)
ign = (d == f)
ign = (d == g)
ign = (e == e)
ign = (e == f)
ign = (e == g)
ign = (f == f)
ign = (f == g)
ign = (g == g)
test()

64
perf-testcases/test-string-compare.rb

@ -0,0 +1,64 @@
def test()
def mk(n)
res = []
i = 0
while i < n do
res[i] = 'x'
i += 1
end
res = res.join()
print(res.length)
print("\n")
return res
end
a = mk(0)
b = mk(1)
c = mk(16)
d = mk(256)
e = mk(4096)
f = mk(65536)
g = mk(1048576)
i = 0
while i < 1e7 do
ign = (a == a)
ign = (a == b)
ign = (a == c)
ign = (a == d)
ign = (a == e)
ign = (a == f)
ign = (a == g)
ign = (b == b)
ign = (b == c)
ign = (b == d)
ign = (b == e)
ign = (b == f)
ign = (b == g)
ign = (c == c)
ign = (c == d)
ign = (c == e)
ign = (c == f)
ign = (c == g)
ign = (d == d)
ign = (d == e)
ign = (d == f)
ign = (d == g)
ign = (e == e)
ign = (e == f)
ign = (e == g)
ign = (f == f)
ign = (f == g)
ign = (g == g)
i += 1
end
end
test()

24
perf-testcases/test-string-intern-match.js

@ -0,0 +1,24 @@
/*
* Test creation and interning of new strings when the intern check
* matches an existing string in the string table. Exercises string
* hashing but limited memory churn.
*/
function test() {
var buf = Duktape.Buffer(2048);
var i;
for (i = 0; i < buf.length; i++) {
buf[i] = i;
}
for (i = 0; i < 1e6; i++) {
void String(buf);
}
}
try {
test();
} catch (e) {
print(e.stack || e);
}

29
perf-testcases/test-string-intern-miss.js

@ -0,0 +1,29 @@
/*
* Test creation and interning of new strings when the intern check
* misses any existing strings in the string table. Exercises string
* hashing and memory churn.
*/
function test() {
var buf = Duktape.Buffer(2048);
var i;
for (i = 0; i < buf.length; i++) {
buf[i] = i;
}
for (i = 0; i < 1e6; i++) {
// make buffer value unique
buf[0] = i;
buf[1] = i >> 8;
buf[2] = i >> 16;
void String(buf);
}
}
try {
test();
} catch (e) {
print(e.stack || e);
}

23
perf-testcases/test-string-plain-concat.js

@ -0,0 +1,23 @@
/*
* Build string with plain concat. Causes O(n^2) behavior in Duktape
* string implementation because every intermediate step is string interned.
*/
function test() {
var i, j;
var t;
for (i = 0; i < 1; i++) {
t = '';
for (j = 0; j < 1e5; j++) {
t += 'x';
//print(t.length);
}
}
}
try {
test();
} catch (e) {
print(e.stack || e);
}

13
perf-testcases/test-string-plain-concat.lua

@ -0,0 +1,13 @@
function test()
local t
for i=1,1 do
t = ''
for j=1,1e5 do
t = t .. 'x'
--print(#t)
end
end
end
test()

14
perf-testcases/test-string-plain-concat.pl

@ -0,0 +1,14 @@
sub test {
my $i, $j, $t;
for ($i = 0; $i < 1; $i++) {
$t = '';
for ($j = 0; $j < 1e5; $j++) {
$t = $t . 'x';
#print(length $t);
#print("\n");
}
}
}
test()

8
perf-testcases/test-string-plain-concat.py

@ -0,0 +1,8 @@
def test():
for i in xrange(1):
t = ''
for j in xrange(int(1e5)):
t += 'x'
#print(len(t))
test()

16
perf-testcases/test-string-plain-concat.rb

@ -0,0 +1,16 @@
def test()
i = 0
while i < 1 do
t = ''
j = 0
while j < 1e5 do
t += 'x'
#print(t.length)
#print("\n")
j += 1
end
i += 1
end
end
test()
Loading…
Cancel
Save