Browse Source

Perf tests for base64

pull/465/head
Sami Vaarala 9 years ago
parent
commit
aacdaf13d1
  1. 39
      tests/perf/test-base64-decode-whitespace.js
  2. 29
      tests/perf/test-base64-decode-whitespace.py
  3. 32
      tests/perf/test-base64-decode.js
  4. 22
      tests/perf/test-base64-decode.py
  5. 31
      tests/perf/test-base64-encode.js
  6. 21
      tests/perf/test-base64-encode.py
  7. 4
      tests/perf/test-hex-encode.js

39
tests/perf/test-base64-decode-whitespace.js

@ -0,0 +1,39 @@
if (typeof print !== 'function') { print = console.log; }
function test() {
var tmp1 = [];
var tmp2 = [];
var tmp3 = [];
var i, n, buf;
print('build');
buf = Duktape.Buffer(1024);
for (i = 0; i < 1024; i++) {
buf[i] = Math.random() * 256;
}
tmp1 = String(buf);
for (i = 0; i < 1024; i++) {
tmp2.push(tmp1);
}
tmp2 = tmp2.join('');
tmp2 = Duktape.enc('base64', tmp2);
// add newlines, intentionally not a multiple of 4
for (i = 0; i < tmp2.length; i += 77) {
tmp3.push(tmp2.substring(i, i + 77));
}
tmp2 = tmp3.join('\n') + '\n';
print(tmp2.length);
print('run');
for (i = 0; i < 1000; i++) {
Duktape.dec('base64', tmp2);
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

29
tests/perf/test-base64-decode-whitespace.py

@ -0,0 +1,29 @@
import math
import random
def test():
tmp1 = []
tmp2 = []
print('build')
for i in xrange(1024):
tmp1.append('%x' % math.floor(random.random() * 16))
tmp1 = ''.join(tmp1)
for i in xrange(1024):
tmp2.append(tmp1)
tmp2 = ''.join(tmp2)
tmp2 = tmp2.encode('base64')
tmp3 = []
i = 0
while i < len(tmp2):
tmp3.append(tmp2[i:i+77])
i += 77
tmp2 = '\n'.join(tmp3) + '\n'
print(len(tmp2))
print('run')
for i in xrange(1000):
ign = tmp2.decode('base64')
test()

32
tests/perf/test-base64-decode.js

@ -0,0 +1,32 @@
if (typeof print !== 'function') { print = console.log; }
function test() {
var tmp1 = [];
var tmp2 = [];
var i, n, buf;
print('build');
buf = Duktape.Buffer(1024);
for (i = 0; i < 1024; i++) {
buf[i] = Math.random() * 256;
}
tmp1 = String(buf);
for (i = 0; i < 1024; i++) {
tmp2.push(tmp1);
}
tmp2 = tmp2.join('');
tmp2 = Duktape.enc('base64', tmp2);
print(tmp2.length);
print('run');
for (i = 0; i < 1000; i++) {
Duktape.dec('base64', tmp2);
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

22
tests/perf/test-base64-decode.py

@ -0,0 +1,22 @@
import math
import random
def test():
tmp1 = []
tmp2 = []
print('build')
for i in xrange(1024):
tmp1.append('%x' % math.floor(random.random() * 16))
tmp1 = ''.join(tmp1)
for i in xrange(1024):
tmp2.append(tmp1)
tmp2 = ''.join(tmp2)
tmp2 = tmp2.encode('base64')
print(len(tmp2))
print('run')
for i in xrange(1000):
ign = tmp2.decode('base64')
test()

31
tests/perf/test-base64-encode.js

@ -0,0 +1,31 @@
if (typeof print !== 'function') { print = console.log; }
function test() {
var tmp1 = [];
var tmp2 = [];
var i, n, buf;
print('build');
buf = Duktape.Buffer(1024);
for (i = 0; i < 1024; i++) {
buf[i] = Math.random() * 256;
}
tmp1 = String(buf);
for (i = 0; i < 1024; i++) {
tmp2.push(tmp1);
}
tmp2 = Duktape.Buffer(tmp2.join(''));
print(tmp2.length);
print('run');
for (i = 0; i < 1000; i++) {
Duktape.enc('base64', tmp2);
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

21
tests/perf/test-base64-encode.py

@ -0,0 +1,21 @@
import math
import random
def test():
tmp1 = []
tmp2 = []
print('build')
for i in xrange(1024):
tmp1.append(chr(int(math.floor(random.random() * 256))))
tmp1 = ''.join(tmp1)
for i in xrange(1024):
tmp2.append(tmp1)
tmp2 = ''.join(tmp2)
print(len(tmp2))
print('run')
for i in xrange(1000):
ign = tmp2.encode('base64')
test()

4
tests/perf/test-hex-encode.js

@ -8,13 +8,13 @@ function test() {
print('build');
buf = Duktape.Buffer(1024);
for (i = 0; i < 1024; i++) {
buf[0] = Math.random() * 256;
buf[i] = Math.random() * 256;
}
tmp1 = String(buf);
for (i = 0; i < 1024; i++) {
tmp2.push(tmp1);
}
tmp2 = tmp2.join('');
tmp2 = Duktape.Buffer(tmp2.join(''));
print(tmp2.length);
print('run');

Loading…
Cancel
Save