Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
460 changes: 222 additions & 238 deletions README.md

Large diffs are not rendered by default.

30 changes: 14 additions & 16 deletions base64/Base64Java.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,33 @@ public static void main(String[] args){
for (int i = 0 ; i < STR_SIZE ; i++) {
sb.append("a");
}
String str = sb.toString();
final byte[] str = sb.toString().getBytes(ISO_8859_1);
String str2 = "";
String str3;

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

out.println("run");
int s = 0;
Long t = System.nanoTime();
final Long t = System.nanoTime();
for (int i = 0 ; i < TRIES ; i++) {
str2 = enc.encodeToString(str.getBytes(ISO_8859_1));
str2 = enc.encodeToString(str);
s += str2.length();
}
out.println("encode: " + s + ", " + (System.nanoTime() - t)/1e9);

// cheat - JIT warming-up - 0-0,3sec
for (int i = 0 ; i < TRIES ; i++) {
dec.decode(str2.getBytes(ISO_8859_1));
}
final byte[] encoded = str2.getBytes(ISO_8859_1);

s = 0;
t = System.nanoTime();
final Long t1 = System.nanoTime();
for (int i = 0 ; i < TRIES ; i++) {
byte[] b_arr = dec.decode(str2.getBytes(ISO_8859_1));
str3 = new String(b_arr, ISO_8859_1);
s += str3.length();
byte[] b_arr = dec.decode(encoded);
s += b_arr.length;
}
out.println("decode: " + s + ", " + (System.nanoTime() - t)/1e9);
final Long now = System.nanoTime();
out.println("decode: " + s + ", " + (now - t1) / 1e9);
out.println("overall time: " + (now - t) / 1e9 + "s");
}
}
20 changes: 13 additions & 7 deletions base64/Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,32 @@ val enc = Base64.getEncoder();
val dec = Base64.getDecoder();

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

var count1 = 0
var encStr = ""

println("JIT warming up")
repeat(5) {
dec.decode(enc.encodeToString(str))
}

println("run")
val t1 = System.nanoTime()
repeat(TRIES) {
encStr = enc.encodeToString(str.toByteArray())
encStr = enc.encodeToString(str)
count1 += encStr.length
}
println("encode: ${count1}, ${(System.nanoTime() - t1) / 1e9}")

var count2 = 0
var decStr: String

val t2 = System.nanoTime()
repeat(TRIES) {
val decBytes = dec.decode(encStr)
decStr = String(decBytes)
count2 += decStr.length
count2 += decBytes.size
}
println("decode: ${count2}, ${(System.nanoTime() - t2) / 1e9}")
}
val now = System.nanoTime()
println("decode: ${count2}, ${(now - t2) / 1e9}")
println("overall time: ${(now - t1) / 1e9}s")
}
2 changes: 1 addition & 1 deletion base64/base64.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
</Project>
27 changes: 11 additions & 16 deletions base64/base64.rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions base64/base64.rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name = "base64_rs"
version = "0.0.1"

[dependencies]
base64 = "0.9.0"
time = "0.1"
base64 = "0.10.1"
time = "0.1.42"

[profile.release]
lto = true
5 changes: 3 additions & 2 deletions base64/build.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#!/bin/sh

crystal build test.cr --release -o base64_cr --no-debug
go build -o base64_go test.go
gccgo -O3 -g -o base64_go_gccgo test.go
g++ -O3 -o base64_cpp test.cpp -lcrypto
gcc -O3 -std=c99 -o base64_c test.c
scalac -optimize test.scala
scalac -opt:l:inline -deprecation test.scala
javac Base64Java.java
kotlinc Test.kt -include-runtime -d Test-kt.jar
dmd -ofbase64_d -O -release -inline test.d
gdc -o base64_d_gdc -O3 -frelease -finline test.d
ldc2 -ofbase64_d_ldc -O5 -release test.d
nim c -o:base64_nim_gcc -d:release --cc:gcc --verbosity:0 test.nim
nim c -o:base64_nim_clang -d:release --cc:clang --verbosity:0 test.nim
julia -e 'Pkg.add("Codecs")'
cargo build --manifest-path base64.rs/Cargo.toml --release && cp ./base64.rs/target/release/base64 ./base64_rs
mcs -debug- -optimize+ test.cs
dotnet build -c Release
Expand Down
10 changes: 10 additions & 0 deletions base64/run-ruby.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

for ruby in \
$HOME/.rubies/ruby-2.6.5 \
$HOME/.rubies/jruby-9.2.8.0 \
$HOME/.rubies/truffleruby-19.2.0.1
do
echo $ruby
../xtime.rb $ruby/bin/ruby test.rb
done
6 changes: 4 additions & 2 deletions base64/run.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh

echo Crystal
../xtime.rb ./base64_cr
echo Go
Expand Down Expand Up @@ -27,7 +29,7 @@ echo Julia
echo Scala
../xtime.rb scala Base64
echo Java
../xtime.rb java -XX:+AggressiveOpts Base64Java
../xtime.rb java Base64Java
echo Kotlin
../xtime.rb java -jar Test-kt.jar
echo Javascript Node
Expand All @@ -43,7 +45,7 @@ echo Ruby
echo Mono
../xtime.rb mono -O=all --gc=sgen test.exe
echo C# .Net Core
../xtime.rb dotnet bin/Release/netcoreapp2.0/base64.dll
../xtime.rb dotnet bin/Release/netcoreapp3.0/base64.dll
echo Perl
../xtime.rb perl -Iperllib/lib/perl5 test.pl
echo Perl XS
Expand Down
3 changes: 2 additions & 1 deletion base64/test-aklomp.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "stdlib.h"
#include "stdio.h"
#include <string.h>
#include "time.h"
#include "libbase64.h"
#include "../lib/config.h"
Expand All @@ -11,7 +12,7 @@ int main() {
const int TRIES = 100;

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

int s = 0;
Expand Down
4 changes: 2 additions & 2 deletions base64/test-xs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
my $str2 = '';

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

($t, $s) = (time, 0);
for (0..TRIES) {
for (1..TRIES) {
$s += length decode_base64 $str2;
}
print "decode: $s, ", (time - $t), "\n";
3 changes: 2 additions & 1 deletion base64/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "stdio.h"
#include "time.h"
#include <stdint.h>
#include <string.h>

typedef unsigned int uint;
const char* chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
Expand Down Expand Up @@ -101,7 +102,7 @@ int main() {
const int TRIES = 100;

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

int s = 0;
Expand Down
8 changes: 4 additions & 4 deletions base64/test.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ str = "a" * STR_SIZE
str2 = ""

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

print "decode: "
t, s = Time.now, 0
t, s = Time.local, 0
TRIES.times do |i|
s += Base64.decode(str2).bytesize
end
puts "#{s}, #{Time.now - t}"
puts "#{s}, #{Time.local - t}"
10 changes: 10 additions & 0 deletions base64/test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ static void Main(string[] args)
string str2 = String.Empty;
int s = 0;

Console.WriteLine("JIT warming up");
for (int i = 0; i < 5; i++)
{
Convert.FromBase64String(Convert.ToBase64String(str1));
}

Console.WriteLine("run");
var sw = Stopwatch.StartNew();
for (int i = 0; i < TRIES; i++)
{
Expand All @@ -24,6 +31,7 @@ static void Main(string[] args)

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

s = 0;
sw.Restart();
Expand All @@ -33,6 +41,8 @@ static void Main(string[] args)
}
sw.Stop();
Console.WriteLine("decode: {0}, {1}", s, sw.Elapsed.TotalSeconds);
overall += sw.Elapsed.TotalSeconds;
Console.WriteLine("overall time: {0}s", overall);
}
}
}
16 changes: 8 additions & 8 deletions base64/test.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Codecs
using Base64

function main(tries)
str_size = 10_000_000
Expand All @@ -8,24 +8,24 @@ function main(tries)
print("encode: ")
t = time()
s = 0
for i in range(0, tries)
str2 = ASCIIString(encode(Base64, str))
for i in 1:tries
str2 = base64encode(str)
s += length(str2)
end
print(s, ", ", time() - t, "\n")

print("decode: ")
t = time()
s = 0
for i in range(0, tries)
s += length(ASCIIString(decode(Base64, str2)))
for i in 1:tries
s += length(base64decode(str2))
end
print(s, ", ", time() - t, "\n")
end

println(STDERR, "warming")
println("JIT warming up")
main(5)

println(STDERR, "bench")
println("bench")
x = @timed main(100)
println(STDERR, "Elapsed: $(x[2]), Allocated: $(x[3]), GC Time: $(x[4])")
println("Elapsed: $(x[2]), Allocated: $(x[3]), GC Time: $(x[4])")
13 changes: 6 additions & 7 deletions base64/test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var STR_SIZE = 10000000;
var TRIES = 100;
const STR_SIZE = 10000000;
const TRIES = 100;

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

var s = 0;
var start = new Date();
for (var i = 0; i < TRIES; i++) {
var b = new Buffer(str);
str2 = b.toString('base64');
s += str2.length;
}
Expand All @@ -16,8 +16,7 @@ console.log("encode: %d, %d", s, ((new Date()) - start) / 1000);
start = new Date();
s = 0
for (var i = 0; i < TRIES; i++) {
var b = new Buffer(str2, 'base64');
var str3 = b.toString();
s += str3.length;
const b = Buffer.from(str2, 'base64');
s += b.length;
}
console.log("decode: %d, %d", s, ((new Date()) - start) / 1000);
Loading