Skip to content

Commit aea2bc2

Browse files
authored
Merge pull request #1 from nuald/update
Updated the toolchain (addressed tickets kostya#129, kostya#133, kostya#158, kostya#159, kostya#164
2 parents a0669bc + 94415d8 commit aea2bc2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+764
-635
lines changed

README.md

Lines changed: 222 additions & 238 deletions
Large diffs are not rendered by default.

base64/Base64Java.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,33 @@ public static void main(String[] args){
1616
for (int i = 0 ; i < STR_SIZE ; i++) {
1717
sb.append("a");
1818
}
19-
String str = sb.toString();
19+
final byte[] str = sb.toString().getBytes(ISO_8859_1);
2020
String str2 = "";
2121
String str3;
2222

23-
// cheat - JIT warming-up - 0,5-1sec
24-
for (int i = 0 ; i < TRIES ; i++) {
25-
enc.encodeToString(str.getBytes(ISO_8859_1)).length();
23+
out.println("JIT warming up");
24+
for (int i = 0 ; i < 5 ; i++) {
25+
dec.decode(enc.encodeToString(str));
2626
}
2727

28+
out.println("run");
2829
int s = 0;
29-
Long t = System.nanoTime();
30+
final Long t = System.nanoTime();
3031
for (int i = 0 ; i < TRIES ; i++) {
31-
str2 = enc.encodeToString(str.getBytes(ISO_8859_1));
32+
str2 = enc.encodeToString(str);
3233
s += str2.length();
3334
}
3435
out.println("encode: " + s + ", " + (System.nanoTime() - t)/1e9);
35-
36-
// cheat - JIT warming-up - 0-0,3sec
37-
for (int i = 0 ; i < TRIES ; i++) {
38-
dec.decode(str2.getBytes(ISO_8859_1));
39-
}
36+
final byte[] encoded = str2.getBytes(ISO_8859_1);
4037

4138
s = 0;
42-
t = System.nanoTime();
39+
final Long t1 = System.nanoTime();
4340
for (int i = 0 ; i < TRIES ; i++) {
44-
byte[] b_arr = dec.decode(str2.getBytes(ISO_8859_1));
45-
str3 = new String(b_arr, ISO_8859_1);
46-
s += str3.length();
41+
byte[] b_arr = dec.decode(encoded);
42+
s += b_arr.length;
4743
}
48-
out.println("decode: " + s + ", " + (System.nanoTime() - t)/1e9);
44+
final Long now = System.nanoTime();
45+
out.println("decode: " + s + ", " + (now - t1) / 1e9);
46+
out.println("overall time: " + (now - t) / 1e9 + "s");
4947
}
5048
}

base64/Test.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,32 @@ val enc = Base64.getEncoder();
77
val dec = Base64.getDecoder();
88

99
fun main(args: Array<String>) {
10-
val str = "a".repeat(STR_SIZE)
10+
val str = "a".repeat(STR_SIZE).toByteArray()
1111

1212
var count1 = 0
1313
var encStr = ""
1414

15+
println("JIT warming up")
16+
repeat(5) {
17+
dec.decode(enc.encodeToString(str))
18+
}
19+
20+
println("run")
1521
val t1 = System.nanoTime()
1622
repeat(TRIES) {
17-
encStr = enc.encodeToString(str.toByteArray())
23+
encStr = enc.encodeToString(str)
1824
count1 += encStr.length
1925
}
2026
println("encode: ${count1}, ${(System.nanoTime() - t1) / 1e9}")
2127

2228
var count2 = 0
23-
var decStr: String
2429

2530
val t2 = System.nanoTime()
2631
repeat(TRIES) {
2732
val decBytes = dec.decode(encStr)
28-
decStr = String(decBytes)
29-
count2 += decStr.length
33+
count2 += decBytes.size
3034
}
31-
println("decode: ${count2}, ${(System.nanoTime() - t2) / 1e9}")
32-
}
35+
val now = System.nanoTime()
36+
println("decode: ${count2}, ${(now - t2) / 1e9}")
37+
println("overall time: ${(now - t1) / 1e9}s")
38+
}

base64/base64.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp2.0</TargetFramework>
3+
<TargetFramework>netcoreapp3.0</TargetFramework>
44
<OutputType>Exe</OutputType>
55
</PropertyGroup>
66
</Project>

base64/base64.rs/Cargo.lock

Lines changed: 11 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

base64/base64.rs/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name = "base64_rs"
33
version = "0.0.1"
44

55
[dependencies]
6-
base64 = "0.9.0"
7-
time = "0.1"
6+
base64 = "0.10.1"
7+
time = "0.1.42"
88

99
[profile.release]
1010
lto = true

base64/build.sh

100644100755
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
#!/bin/sh
2+
13
crystal build test.cr --release -o base64_cr --no-debug
24
go build -o base64_go test.go
35
gccgo -O3 -g -o base64_go_gccgo test.go
46
g++ -O3 -o base64_cpp test.cpp -lcrypto
57
gcc -O3 -std=c99 -o base64_c test.c
6-
scalac -optimize test.scala
8+
scalac -opt:l:inline -deprecation test.scala
79
javac Base64Java.java
810
kotlinc Test.kt -include-runtime -d Test-kt.jar
911
dmd -ofbase64_d -O -release -inline test.d
1012
gdc -o base64_d_gdc -O3 -frelease -finline test.d
1113
ldc2 -ofbase64_d_ldc -O5 -release test.d
1214
nim c -o:base64_nim_gcc -d:release --cc:gcc --verbosity:0 test.nim
1315
nim c -o:base64_nim_clang -d:release --cc:clang --verbosity:0 test.nim
14-
julia -e 'Pkg.add("Codecs")'
1516
cargo build --manifest-path base64.rs/Cargo.toml --release && cp ./base64.rs/target/release/base64 ./base64_rs
1617
mcs -debug- -optimize+ test.cs
1718
dotnet build -c Release

base64/run-ruby.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
for ruby in \
4+
$HOME/.rubies/ruby-2.6.5 \
5+
$HOME/.rubies/jruby-9.2.8.0 \
6+
$HOME/.rubies/truffleruby-19.2.0.1
7+
do
8+
echo $ruby
9+
../xtime.rb $ruby/bin/ruby test.rb
10+
done

base64/run.sh

100644100755
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/bin/sh
2+
13
echo Crystal
24
../xtime.rb ./base64_cr
35
echo Go
@@ -27,7 +29,7 @@ echo Julia
2729
echo Scala
2830
../xtime.rb scala Base64
2931
echo Java
30-
../xtime.rb java -XX:+AggressiveOpts Base64Java
32+
../xtime.rb java Base64Java
3133
echo Kotlin
3234
../xtime.rb java -jar Test-kt.jar
3335
echo Javascript Node
@@ -43,7 +45,7 @@ echo Ruby
4345
echo Mono
4446
../xtime.rb mono -O=all --gc=sgen test.exe
4547
echo C# .Net Core
46-
../xtime.rb dotnet bin/Release/netcoreapp2.0/base64.dll
48+
../xtime.rb dotnet bin/Release/netcoreapp3.0/base64.dll
4749
echo Perl
4850
../xtime.rb perl -Iperllib/lib/perl5 test.pl
4951
echo Perl XS

base64/test-aklomp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "stdlib.h"
22
#include "stdio.h"
3+
#include <string.h>
34
#include "time.h"
45
#include "libbase64.h"
56
#include "../lib/config.h"
@@ -11,7 +12,7 @@ int main() {
1112
const int TRIES = 100;
1213

1314
char *str = (char*) malloc(STR_SIZE + 1);
14-
for (int i = 0; i < STR_SIZE; i++) { str[i] = 'a'; }
15+
memset(str, 'a', STR_SIZE);
1516
str[STR_SIZE] = '\0';
1617

1718
int s = 0;

base64/test-xs.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
my $str2 = '';
1111

1212
my ($t, $s) = (time, 0);
13-
for (0..TRIES) {
13+
for (1..TRIES) {
1414
$str2 = encode_base64 $str, '';
1515
$s += length $str2;
1616
}
1717
print "encode: $s, ", (time - $t), "\n";
1818

1919
($t, $s) = (time, 0);
20-
for (0..TRIES) {
20+
for (1..TRIES) {
2121
$s += length decode_base64 $str2;
2222
}
2323
print "decode: $s, ", (time - $t), "\n";

base64/test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "stdio.h"
33
#include "time.h"
44
#include <stdint.h>
5+
#include <string.h>
56

67
typedef unsigned int uint;
78
const char* chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -101,7 +102,7 @@ int main() {
101102
const int TRIES = 100;
102103

103104
char *str = (char*) malloc(STR_SIZE + 1);
104-
for (int i = 0; i < STR_SIZE; i++) { str[i] = 'a'; }
105+
memset(str, 'a', STR_SIZE);
105106
str[STR_SIZE] = '\0';
106107

107108
int s = 0;

base64/test.cr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ str = "a" * STR_SIZE
77
str2 = ""
88

99
print "encode: "
10-
t, s = Time.now, 0
10+
t, s = Time.local, 0
1111
TRIES.times do |i|
1212
str2 = Base64.strict_encode(str)
1313
s += str2.bytesize
1414
end
15-
puts "#{s}, #{Time.now - t}"
15+
puts "#{s}, #{Time.local - t}"
1616

1717
print "decode: "
18-
t, s = Time.now, 0
18+
t, s = Time.local, 0
1919
TRIES.times do |i|
2020
s += Base64.decode(str2).bytesize
2121
end
22-
puts "#{s}, #{Time.now - t}"
22+
puts "#{s}, #{Time.local - t}"

base64/test.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ static void Main(string[] args)
1515
string str2 = String.Empty;
1616
int s = 0;
1717

18+
Console.WriteLine("JIT warming up");
19+
for (int i = 0; i < 5; i++)
20+
{
21+
Convert.FromBase64String(Convert.ToBase64String(str1));
22+
}
23+
24+
Console.WriteLine("run");
1825
var sw = Stopwatch.StartNew();
1926
for (int i = 0; i < TRIES; i++)
2027
{
@@ -24,6 +31,7 @@ static void Main(string[] args)
2431

2532
sw.Stop();
2633
Console.WriteLine("encode: {0}, {1}", s, sw.Elapsed.TotalSeconds);
34+
var overall = sw.Elapsed.TotalSeconds;
2735

2836
s = 0;
2937
sw.Restart();
@@ -33,6 +41,8 @@ static void Main(string[] args)
3341
}
3442
sw.Stop();
3543
Console.WriteLine("decode: {0}, {1}", s, sw.Elapsed.TotalSeconds);
44+
overall += sw.Elapsed.TotalSeconds;
45+
Console.WriteLine("overall time: {0}s", overall);
3646
}
3747
}
3848
}

base64/test.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Codecs
1+
using Base64
22

33
function main(tries)
44
str_size = 10_000_000
@@ -8,24 +8,24 @@ function main(tries)
88
print("encode: ")
99
t = time()
1010
s = 0
11-
for i in range(0, tries)
12-
str2 = ASCIIString(encode(Base64, str))
11+
for i in 1:tries
12+
str2 = base64encode(str)
1313
s += length(str2)
1414
end
1515
print(s, ", ", time() - t, "\n")
1616

1717
print("decode: ")
1818
t = time()
1919
s = 0
20-
for i in range(0, tries)
21-
s += length(ASCIIString(decode(Base64, str2)))
20+
for i in 1:tries
21+
s += length(base64decode(str2))
2222
end
2323
print(s, ", ", time() - t, "\n")
2424
end
2525

26-
println(STDERR, "warming")
26+
println("JIT warming up")
2727
main(5)
2828

29-
println(STDERR, "bench")
29+
println("bench")
3030
x = @timed main(100)
31-
println(STDERR, "Elapsed: $(x[2]), Allocated: $(x[3]), GC Time: $(x[4])")
31+
println("Elapsed: $(x[2]), Allocated: $(x[3]), GC Time: $(x[4])")

base64/test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
var STR_SIZE = 10000000;
2-
var TRIES = 100;
1+
const STR_SIZE = 10000000;
2+
const TRIES = 100;
33

4-
var str = ""; for (var i = 0; i < STR_SIZE; i++) str += "a";
4+
const str = "a".repeat(STR_SIZE);
55
var str2 = "";
6+
const b = Buffer.from(str);
67

78
var s = 0;
89
var start = new Date();
910
for (var i = 0; i < TRIES; i++) {
10-
var b = new Buffer(str);
1111
str2 = b.toString('base64');
1212
s += str2.length;
1313
}
@@ -16,8 +16,7 @@ console.log("encode: %d, %d", s, ((new Date()) - start) / 1000);
1616
start = new Date();
1717
s = 0
1818
for (var i = 0; i < TRIES; i++) {
19-
var b = new Buffer(str2, 'base64');
20-
var str3 = b.toString();
21-
s += str3.length;
19+
const b = Buffer.from(str2, 'base64');
20+
s += b.length;
2221
}
2322
console.log("decode: %d, %d", s, ((new Date()) - start) / 1000);

0 commit comments

Comments
 (0)