From 94415d80d085352d05167015d545f93840973600 Mon Sep 17 00:00:00 2001 From: Alexander Slesarev Date: Fri, 4 Oct 2019 12:35:11 -0600 Subject: [PATCH] Updated the toolchain (addressed tickets #129, #133, #158, #159, #164, #170, #179). Removed Ruby Topaz and Rubinous as these are not the active projects anymore (the latter has some activity, but it neither can be properly compiled nor compatible with the used Ruby code). Fixed memory consumption calculation to include children processes (e.g. for Scala as it invokes the actual JVM process as a child). Minor tweaks to BF tests (normalizing data types and allocations if possible). Applied changes from PR #157, #167, #177, #175. Added relevant warming up for .NET projects (issue #154), however it barely changed the results. Replaced D Mir GLAS (not supported anymore) with D lubeck (another linear algebra library also utilizing D Mir) test. --- README.md | 460 +++++++++--------- base64/Base64Java.java | 30 +- base64/Test.kt | 20 +- base64/base64.csproj | 2 +- base64/base64.rs/Cargo.lock | 27 +- base64/base64.rs/Cargo.toml | 4 +- base64/build.sh | 5 +- base64/run-ruby.sh | 10 + base64/run.sh | 6 +- base64/test-aklomp.c | 3 +- base64/test-xs.pl | 4 +- base64/test.c | 3 +- base64/test.cr | 8 +- base64/test.cs | 10 + base64/test.jl | 16 +- base64/test.js | 13 +- base64/test.php | 3 +- base64/test.pl | 4 +- base64/test.scala | 21 +- brainfuck/brainfuck.csproj | 2 +- brainfuck/brainfuck.flx | 45 +- brainfuck/brainfuck.jl | 20 +- brainfuck/brainfuck.nim | 2 - brainfuck/brainfuck.scala | 4 +- brainfuck/build.sh | 6 +- brainfuck/run.sh | 6 +- brainfuck/run2.sh | 2 + brainfuck2/bf.cpp | 3 +- brainfuck2/bf.cs | 17 +- brainfuck2/bf.fs | 15 + brainfuck2/bf.go | 2 +- brainfuck2/bf.java | 69 ++- brainfuck2/bf.nim | 4 - brainfuck2/bf.scala | 52 +- brainfuck2/bf2.kt | 7 +- brainfuck2/brainfuck2.csproj | 2 +- brainfuck2/build.sh | 8 +- brainfuck2/run-ruby.sh | 10 + brainfuck2/run.sh | 14 +- brainfuck2/run2.sh | 6 +- havlak/build.sh | 4 +- havlak/havlak.csproj | 2 +- havlak/havlak.go | 15 +- havlak/havlak.nim | 42 +- havlak/havlak.scala | 9 +- havlak/run.sh | 4 +- json/build.sh | 10 +- json/json-clj/src/json.clj | 13 +- json/json-hs/stack.yaml | 4 +- json/json-hs/stack.yaml.lock | 19 + .../src/main/java/bench/TestJava.java | 2 +- json/json-scala/build.sbt | 4 +- json/json-scala/project/build.properties | 2 +- json/json-scala/project/plugins.sbt | 2 +- json/json-scala/src/main/scala/JsonTest.scala | 2 +- json/json.csproj | 2 +- json/json.rs/Cargo.lock | 2 + json/run-ruby.sh | 10 + json/run.sh | 4 +- json/test.cs | 14 +- json/test.jl | 10 +- json/test_libjson.cpp | 33 +- matmul/build.sh | 6 +- matmul/matmul-native.jl | 6 +- matmul/matmul.cr | 4 +- matmul/matmul.cs | 12 +- matmul/matmul.csproj | 2 +- matmul/matmul.d | 18 +- matmul/matmul.java | 2 +- matmul/matmul.jl | 6 +- matmul/matmul.kt | 2 +- matmul/matmul.nim | 27 +- matmul/matmul.scala | 2 +- matmul/matmul.swift | 16 +- matmul/matmul_d_lubeck.d | 53 ++ matmul/matmul_d_mir.d | 58 --- matmul/run-ruby.sh | 10 + matmul/run.sh | 10 +- xtime.rb | 11 +- 79 files changed, 764 insertions(+), 635 deletions(-) mode change 100644 => 100755 base64/build.sh create mode 100755 base64/run-ruby.sh mode change 100644 => 100755 base64/run.sh mode change 100644 => 100755 brainfuck/build.sh mode change 100644 => 100755 brainfuck/run.sh mode change 100644 => 100755 brainfuck/run2.sh mode change 100644 => 100755 brainfuck2/build.sh create mode 100755 brainfuck2/run-ruby.sh mode change 100644 => 100755 brainfuck2/run.sh mode change 100644 => 100755 brainfuck2/run2.sh mode change 100644 => 100755 havlak/build.sh mode change 100644 => 100755 havlak/run.sh mode change 100644 => 100755 json/build.sh create mode 100644 json/json-hs/stack.yaml.lock create mode 100755 json/run-ruby.sh mode change 100644 => 100755 matmul/build.sh create mode 100644 matmul/matmul_d_lubeck.d delete mode 100644 matmul/matmul_d_mir.d create mode 100755 matmul/run-ruby.sh mode change 100644 => 100755 matmul/run.sh diff --git a/README.md b/README.md index c6c1a1d4..a50011ec 100644 --- a/README.md +++ b/README.md @@ -3,284 +3,268 @@ Some benchmarks of different languages # Brainfuck v2.0 -[Brainfuck v2.0](https://github.com/kostya/benchmarks/tree/master/brainfuck2) -[Brainfuck v1.0](https://github.com/kostya/benchmarks/tree/master/brainfuck) +[Brainfuck v2.0](brainfuck2) +[Brainfuck v1.0](brainfuck) ### bench.b | Language | Time, s | Memory, MiB | | --------------- | ------- | ----------- | -| Kotlin | 1.78 | 28.4 | -| C++ Gcc | 1.94 | 1.0 | -| Rust | 2.16 | 4.8 | -| Nim Gcc | 2.50 | 0.6 | -| D Gdc | 2.61 | 1.4 | -| Go | 2.79 | 0.9 | -| D Ldc | 2.85 | 1.0 | -| Nim Clang | 3.11 | 0.8 | -| ML MLton | 3.14 | 0.7 | -| Crystal | 3.37 | 1.3 | -| Go Gcc | 3.38 | 10.0 | -| C# .Net Core | 3.40 | 18.7 | -| Scala | 3.43 | 120.12 | -| Java | 4.03 | 513.8 | -| OCaml | 4.04 | 2.7 | -| D Dmd | 5.23 | 1.0 | -| C# Mono | 6.14 | 14.6 | -| Javascript V8 | 6.53 | 7.9 | -| F# Mono | 7.52 | 21.1 | -| Javascript Node | 7.85 | 18.6 | -| Haskell (MArray)| 7.95 | 2.2 | -| LuaJIT | 12.61 | 1.0 | -| Chez Scheme | 20.15 | 25.7 | -| Python PyPy | 22.14 | 75.9 | -| Haskell | 25.34 | 2.2 | -| Racket | 27.76 | 57.9 | -| Ruby truffle | 33.79 | 1089.8 | -| Ruby Topaz | 59.53 | 36.5 | -| Ruby Rbx | 120.38 | 32.3 | -| Ruby Jruby | 129.75 | 267.6 | -| Ruby Jruby9k | 134.18 | 286.8 | -| Ruby | 147.32 | 7.4 | -| Lua 5.1 | 182.74 | 1.0 | -| Elixir | 208.19 | 31.9 | -| Python | 314.79 | 4.9 | -| Python3 | 412.13 | 5.5 | -| Tcl (FP) | 457.33 | 2.5 | -| Tcl (OO) | 821.96 | 2.5 | -| Perl | 872.44 | 2.5 | +| Kotlin | 1.56 | 38.9 | +| C++ Gcc | 1.74 | 1.8 | +| D Gdc | 2.32 | 6.3 | +| Java | 2.54 | 39.3 | +| Rust | 2.58 | 0.9 | +| Go | 2.65 | 1.4 | +| D Ldc | 2.74 | 1.5 | +| Go Gcc | 2.80 | 19.1 | +| ML MLton | 2.85 | 1.2 | +| C# .Net Core | 3.00 | 28.0 | +| Crystal | 3.03 | 2.7 | +| Scala | 3.51 | 136.3 | +| OCaml | 3.61 | 4.0 | +| Nim Gcc | 3.83 | 0.8 | +| D Dmd | 4.60 | 1.9 | +| Nim Clang | 5.06 | 1.3 | +| C# Mono | 6.13 | 17.7 | +| Javascript Node | 6.23 | 31.2 | +| Haskell (MArray)| 7.06 | 4.1 | +| F# Mono | 7.34 | 25.4 | +| Javascript V8 | 7.61 | 24.1 | +| LuaJIT | 10.89 | 1.3 | +| Racket | 16.85 | 62.2 | +| Python PyPy | 17.75 | 95.0 | +| Chez Scheme | 18.48 | 29.4 | +| Haskell | 23.01 | 4.1 | +| Ruby truffle | 29.21 | 603.3 | +| Ruby | 119.07 | 13.7 | +| Lua 5.3 | 131.13 | 1.5 | +| Ruby JRuby | 142.68 | 240.1 | +| Elixir | 155.58 | 41.4 | +| Python | 282.38 | 6.9 | +| Python3 | 284.03 | 8.9 | +| Tcl (FP) | 362.41 | 4.6 | +| Perl | 530.66 | 5.0 | +| Tcl (OO) | 701.28 | 5.0 | ### mandel.b -[Mandel in Brainfuck](https://github.com/kostya/benchmarks/blob/master/brainfuck2/mandel.b) +[Mandel in Brainfuck](brainfuck2/mandel.b) | Language | Time, s | Memory, MiB | | --------------- | ------- | ----------- | -| C++ Gcc | 20.49 | 1.7 | -| Crystal | 25.28 | 1.5 | -| Rust | 27.18 | 4.8 | -| D Gdc | 27.40 | 2.4 | -| Go Gcc | 28.06 | 11.4 | -| Nim Gcc | 30.78 | 2.7 | -| D Ldc | 31.21 | 1.8 | -| C# .Net Core | 34.93 | 21.4 | -| ML MLton | 36.03 | 2.5 | -| Nim Clang | 37.22 | 2.9 | -| Kotlin | 40.79 | 34.9 | -| OCaml | 52.18 | 5.3 | -| Scala | 58.51 | 120.12 | -| Java | 58.86 | 423.9 | -| D Dmd | 62.69 | 1.7 | -| Go | 65.78 | 2.2 | -| C# Mono | 70.90 | 12.6 | -| Javascript Node | 76.37 | 19.9 | -| Haskell (MArray)| 124.60 | 3.2 | -| LuaJIT | 131.46 | 1.9 | -| Python PyPy | 133.73 | 76.0 | +| C++ Gcc | 22.98 | 3.7 | +| D Ldc | 24.96 | 3.7 | +| D Gdc | 25.31 | 7.1 | +| Crystal | 25.60 | 3.1 | +| Rust | 25.74 | 2.0 | +| Kotlin | 27.29 | 45.3 | +| Scala | 30.72 | 142.6 | +| C# .Net Core | 31.40 | 29.7 | +| ML MLton | 32.35 | 4.0 | +| Java | 32.88 | 45.4 | +| Go Gcc | 33.72 | 34.5 | +| OCaml | 44.71 | 11.7 | +| Go | 47.86 | 3.1 | +| Nim Gcc | 48.84 | 3.3 | +| Nim Clang | 54.24 | 3.7 | +| D Dmd | 58.42 | 4.3 | +| Javascript Node | 64.23 | 34.4 | +| C# Mono | 78.52 | 18.1 | +| Python PyPy | 105.04 | 96.3 | +| Haskell (MArray)| 107.81 | 5.4 | +| LuaJIT | 110.26 | 3.0 | | Ruby truffle | 138.00 | 1014.1 | -| F# Mono | 166.38 | 29.1 | -| Chez Scheme | 258.54 | 27.8 | -| Ruby Topaz | 305.79 | 38.8 | -| Racket | 339.10 | 68.0 | +| F# Mono | 166.75 | 33.5 | +| Racket | 203.15 | 63.9 | +| Chez Scheme | 212.33 | 29.3 | # Base64 -[Base64](https://github.com/kostya/benchmarks/tree/master/base64) +[Base64](base64) | Language | Time, s | Memory, MiB | | --------------- | ------- | ----------- | -| C aklomp SSSE3 | 0.93 | 32.3 | -| C | 1.85 | 32.2 | -| Rust | 1.92 | 42.9 | -| D Ldc | 2.01 | 54.4 | -| Crystal | 2.59 | 58.5 | -| Ruby | 2.95 | 167.7 | -| D Gdc | 3.04 | 54.1 | -| Perl XS | 3.63 | 47.9 | -| Ruby Rbx | 4.29 | 30.7 | -| Nim Gcc | 4.29 | 57.8 | -| Nim Clang | 4.34 | 57.9 | -| Julia | 4.41 | 190.0 | -| C++ Openssl | 5.45 | 65.2 | -| Javascript Node | 5.53 | 475.8 | -| Php | 6.34 | 53.4 | -| C# .Net Core | 6.63 | 121.1 | -| D | 7.18 | 55.3 | -| Tcl | 7.20 | 66.0 | -| Go | 7.56 | 93.1 | -| Python | 7.62 | 52.6 | -| Python PyPy | 8.05 | 153.9 | -| Python3 | 8.13 | 54.5 | -| C# Mono | 9.01 | 71.7 | -| Java | 9.06 | 971.2 | -| Kotlin | 9.75 | 932.9 | -| Scala | 10.69 | 292.5 | -| Ruby JRuby9K | 12.16 | 530.6 | -| Ruby JRuby | 12.65 | 514.9 | -| Ruby truffle | 17.17 | 908.3 | -| Perl | 33.30 | 99.7 | -| Go Gcc | 39.56 | 185.5 | +| C aklomp SSSE3 | 0.52 | 33.1 | +| C | 1.67 | 33.2 | +| Rust | 1.88 | 46.4 | +| Crystal | 2.10 | 57.3 | +| D Ldc | 2.18 | 54.0 | +| Ruby | 2.48 | 197.9 | +| Javascript Node | 2.76 | 220.9 | +| Java | 2.93 | 351.1 | +| Perl XS | 3.24 | 50.3 | +| D Gdc | 3.29 | 57.8 | +| Kotlin | 3.32 | 403.4 | +| Scala | 3.64 | 128.2 | +| Go | 3.65 | 178.5 | +| Go Gcc | 4.47 | 219.1 | +| C# .Net Core | 4.70 | 224.4 | +| Php | 4.90 | 57.2 | +| C++ Openssl | 5.53 | 68.1 | +| Python3 | 6.01 | 44.1 | +| D | 6.11 | 54.3 | +| Tcl | 6.20 | 68.7 | +| Python PyPy | 7.40 | 156.1 | +| Python | 7.60 | 55.0 | +| Nim Gcc | 7.85 | 58.9 | +| C# Mono | 7.89 | 127.6 | +| Nim Clang | 8.20 | 59.4 | +| Julia | 9.18 | 355.4 | +| Ruby JRuby | 12.29 | 254.7 | +| Perl | 26.60 | 142.6 | +| Ruby truffle | 29.37 | 478.4 | # Json -[Json](https://github.com/kostya/benchmarks/tree/master/json) +[Json](json) | Language | Time, s | Memory, MiB | | --------------- | ------- | ----------- | -| D Gdc Fast | 0.35 | 234.1 | -| Rust Pull | 0.49 | 207.7 | -| Rust Struct | 0.50 | 226.2 | -| C++ Rapid SAX | 0.72 | 1.0 | -| C++ Gason | 0.83 | 582.2 | -| C++ Rapid | 0.94 | 243.6 | -| Java | 1.28 | 371.2 | -| Scala | 1.44 | 457.2 | -| Rust Value | 1.82 | 1675.8 | -| Crystal Schema | 1.87 | 304.6 | -| Crystal | 2.41 | 1119.2 | -| Perl XS | 2.68 | 888.4 | -| Javascript Node | 3.33 | 871.0 | -| Python3 ujson | 4.15 | 1303.2 | -| Nim Clang | 4.22 | 1335.8 | -| Crystal Pull | 4.24 | 3.3 | -| Nim Gcc | 4.70 | 1335.0 | -| Go | 4.92 | 479.3 | -| Python ujson | 5.07 | 1352.9 | -| Q | 5.18 | 684.0 | -| Python PyPy | 5.35 | 1534.5 | -| C++ LibJson | 5.49 | 2796.3 | -| Clojure | 5.81 | 1148.5 | -| Python3 | 5.82 | 1037.8 | -| C# .Net Core | 5.89 | 836.9 | -| Php | 6.37 | 1502.0 | -| D Ldc | 7.13 | 1357.0 | -| Haskell | 8.31 | 70.5 | -| Ruby | 8.34 | 897.3 | -| D Gdc | 8.89 | 1357.2 | -| Ruby Yajl | 9.52 | 1054.6 | -| Python | 9.85 | 1409.1 | -| C# Mono | 10.57 | 812.1 | -| Julia | 11.89 | 2622.4 | -| D | 12.42 | 1417.1 | -| JQ | 14.92 | 1714.5 | -| C++ Boost | 16.44 | 2915.2 | -| Ruby JRuby9K | 16.53 | 2050.5 | -| Go Gcc | 17.64 | 473.1 | -| Ruby JRuby | 21.98 | 2761.1 | -| Perl | 46.02 | 1635.4 | -| Ruby Rbx | 67.13 | 4681.0 | -| Ruby truffle | - | 1251.2 | +| D Gdc Fast | 0.30 | 191.3 | +| Rust Pull | 0.38 | 202.6 | +| Rust Struct | 0.39 | 225.2 | +| C++ Rapid SAX | 0.55 | 1.8 | +| C++ Rapid | 0.78 | 218.5 | +| C++ Gason | 0.85 | 591.0 | +| Java | 0.99 | 383.8 | +| Scala | 1.22 | 536.8 | +| Rust Value | 2.08 | 1745.9 | +| Javascript Node | 2.22 | 507.6 | +| Crystal Schema | 2.23 | 282.0 | +| Perl XS | 2.37 | 966.4 | +| Crystal | 2.94 | 962.1 | +| Clojure | 3.24 | 1676.0 | +| Go | 3.42 | 511.2 | +| Php | 3.43 | 1476.7 | +| Python3 ujson | 3.61 | 1184.0 | +| Julia | 4.14 | 2369.6 | +| Python3 | 4.65 | 910.4 | +| Python PyPy | 4.78 | 1293.0 | +| Crystal Pull | 4.94 | 4.3 | +| Python ujson | 5.10 | 1404.7 | +| Go Gcc | 5.28 | 456.9 | +| C++ LibJson | 5.46 | 2888.8 | +| Nim Gcc | 5.46 | 1321.2 | +| Nim Clang | 5.73 | 1321.6 | +| Q | 5.85 | 691.5 | +| Haskell | 6.17 | 9.9 | +| Ruby | 6.33 | 842.4 | +| C# .Net Core | 6.67 | 842.2 | +| D Ldc | 6.69 | 1546.7 | +| Ruby Yajl | 6.94 | 840.4 | +| D Gdc | 7.52 | 1362.2 | +| Python | 8.99 | 1411.1 | +| C++ Boost | 9.53 | 2952.4 | +| C# Mono | 10.16 | 859.0 | +| JQ | 10.43 | 1321.9 | +| D Dmd | 12.35 | 1546.9 | +| Ruby JRuby | 13.70 | 2189.4 | +| Perl | 38.04 | 1415.5 | +| Ruby truffle | 159.02 | 5162.5 | # Matmul -[Matmul](https://github.com/kostya/benchmarks/tree/master/matmul) +[Matmul](matmul) | Language | Time, s | Memory, MiB | | --------------- | ------- | ----------- | -| Julia Native Thr| 0.11 | 148.3 | -| Julia Native | 0.31 | 175.8 | -| D Mir GLAS | 0.32 | 56.7 | -| D Ldc | 2.17 | 73.0 | -| D | 2.30 | 71.3 | -| D Gdc | 2.30 | 73.0 | -| Python Numpy | 3.08 | 65.3 | -| Java | 3.50 | 136.2 | -| Rust | 3.58 | 76.8 | -| Scala | 3.62 | 136.2 | -| Kotlin | 3.62 | 132.2 | -| C | 3.64 | 69.2 | -| Nim Clang | 3.68 | 167.8 | -| Crystal | 3.70 | 55.8 | -| Nim Gcc | 3.75 | 188.2 | -| Julia | 3.76 | 172.2 | -| Go | 3.77 | 59.6 | -| Go Gcc | 3.90 | 84.5 | -| Swift | 4.48 | 110.8 | -| Javascript Node | 6.06 | 89.6 | -| Javascript V8 | 6.87 | 81.5 | -| Python PyPy | 7.98 | 121.7 | -| C# .Net Core | 9.17 | 87.4 | -| C# Mono | 15.17 | 83.6 | -| Ruby truffle | 35.43 | 934.2 | -| Ruby Topaz | 81.41 | 206.2 | -| Ruby | 354.98 | 78.7 | -| Python | 447.39 | 74.0 | -| Ruby JRuby | 416.12 | 582.4 | -| Ruby JRuby9k | 467.59 | 608.3 | -| Ruby Rbx | 591.70 | 325.0 | -| Perl | 666.46 | 604.1 | -| Tcl | 1066.66 | 279.9 | +| D lubeck | 0.12 | 13.9 | +| Julia Native Thr| 0.13 | 216.9 | +| Julia Native | 0.29 | 214.7 | +| Python Numpy | 1.08 | 52.3 | +| D Ldc | 2.00 | 73.2 | +| D | 2.24 | 73.1 | +| D Gdc | 2.36 | 76.8 | +| C | 3.11 | 69.7 | +| Rust | 3.17 | 70.7 | +| Julia | 3.22 | 246.5 | +| Crystal | 3.32 | 63.3 | +| Go Gcc | 3.41 | 106.6 | +| Go | 3.54 | 60.4 | +| Kotlin | 3.59 | 129.6 | +| Scala | 3.67 | 171.5 | +| Java | 3.81 | 129.5 | +| Nim Clang | 4.24 | 73.4 | +| Javascript Node | 4.36 | 101.7 | +| Swift | 7.13 | 186.4 | +| Javascript V8 | 5.92 | 95.0 | +| Python PyPy | 8.18 | 132.9 | +| C# .Net Core | 8.21 | 102.9 | +| Nim Gcc | 8.64 | 72.5 | +| C# Mono | 14.44 | 88.4 | +| Ruby truffle | 59.52 | 580.5 | +| Ruby | 246.34 | 83.0 | +| Python | 340.32 | 76.0 | +| Ruby JRuby | 534.32 | 1085.6 | +| Tcl | 481.88 | 281.1 | +| Perl | 558.50 | 606.7 | # Havlak -[Havlak](https://github.com/kostya/benchmarks/tree/master/havlak) +[Havlak](havlak) | Language | Time, s | Memory, MiB | | --------------- | ------- | ----------- | -| Crystal | 12.26 | 398.9 | -| Nim Gcc | 15.53 | 1003.2 | -| Nim Clang | 16.02 | 1011.4 | -| C++ | 17.72 | 174.5 | -| D Ldc | 22.41 | 467.9 | -| D Gdc | 24.98 | 451.6 | -| D | 28.90 | 418.2 | -| Scala | 32.18 | 363.0 | -| Go | 32.17 | 366.4 | -| Go Gcc | 32.94 | 365.7 | -| C# Mono | 40.54 | 270.0 | -| Python PyPy | 50.21 | 797.0 | -| C# .Net Core | 54.57 | 519.519.519.0 -| Python | 396.54 | 724.0 | - - +| Crystal | 10.04 | 228.2 | +| Nim Gcc | 15.13 | 476.0 | +| Nim Clang | 15.75 | 459.3 | +| C++ | 16.16 | 179.2 | +| Scala | 22.84 | 384.9 | +| D Ldc | 23.37 | 460.1 | +| Go | 24.24 | 347.0 | +| D | 28.51 | 461.4 | +| D Gdc | 30.17 | 419.3 | +| C# Mono | 31.33 | 326.7 | +| Go Gcc | 36.52 | 430.7 | +| Python PyPy | 40.09 | 624.4 | +| C# .Net Core | 43.10 | 542.1 | +| Python | 345.14 | 725.5 | # Hardware: -Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz (Ubuntu 14.04.1 LTS x86_64) +Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz (Ubuntu 18.04.3 LTS x86_64) # Versions: -* gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2 -* Nim Compiler Version 0.17.0 (2017-05-17) [Linux: amd64] -* `Crystal 0.23.1 [e2a1389e8] (2017-07-13) LLVM 3.8.1` -* go version go1.9 linux/amd64 -* gccgo (Ubuntu 4.9.1-0ubuntu1) 4.9.1 -* DMD64 D Compiler v2.068.0 -* gdc (gdcproject.org 20161225-v2.068.2_gcc6) 6.3.0 -* LDC - the LLVM D compiler (1.4.0-beta1): based on DMD v2.074.1 and LLVM 4.0.1 -* V8 version 3.29.62 (candidate) -* rustc 1.19.0 (0ade33941 2017-07-17) -* Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45) -* Nodejs v8.4.0 -* PyPy 5.6.0 with GCC 4.8.2 -* topaz (ruby-1.9.3p125) (git rev b95c858) [x86_64-linux] -* ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] -* Python 2.7.6 -* Python 3.5.2 -* rubinius 2.2.10 (2.1.0 bf61ae2e 2014-06-27 JI) [x86_64-linux-gnu] -* jruby 1.7.20 (1.9.3p551) 2015-05-04 3086e6a on Java HotSpot(TM) 64-Bit Server VM 1.8.0_45-b14 +jit [linux-amd64] -* jruby 9.0.0.0.pre2 (2.2.2) 2015-04-28 2755ae0 Java HotSpot(TM) 64-Bit Server VM 25.45-b02 on 1.8.0_45-b14 +jit [linux-amd64] -* java version "1.8.0_45" Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode) -* julia version 0.4.3 -* clang version 3.9.0 (tags/RELEASE_390/final) -* Mono JIT compiler version 4.0.1 (tarball Tue May 12 15:39:23 UTC 2015) -* rock 0.9.10-head codename sapphire, built on Wed Jul 1 20:09:58 2015 -* Felix version 15.04.03 -* Q KDB+ 3.3 2015.09.02 Copyright (C) 1993-2015 Kx Systems -* perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-linux-gnu-thread-multi -* The Glorious Glasgow Haskell Compilation System, version 7.10.2 +* gcc (Ubuntu 9.1.0-2ubuntu2~18.04) 9.1.0 +* Nim Compiler Version 1.0.0 [Linux: amd64] +* `Crystal 0.31.1 [0e2e1d067] (2019-09-30) LLVM 8.0.0` +* go version go1.13.1 linux/amd64 +* gccgo (Ubuntu 9.1.0-2ubuntu2~18.04) 9.1.0 +* DMD64 D Compiler v2.088.0 +* gdc (Ubuntu 9.1.0-2ubuntu2~18.04) 9.1.0 +* LDC - the LLVM D compiler (1.18.0-beta1): based on DMD v2.088.0 and LLVM 8.0.1 +* V8 version 7.9.0 (candidate) +* rustc 1.38.0 (625451e37 2019-09-23) +* Scala 2.13.0 (OpenJDK 64-Bit Server VM, Java 11.0.4) +* Nodejs v12.10.0 +* PyPy 7.1.1 with GCC 7.4.0 +* ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux] +* Python 2.7.15+ +* Python 3.6.8 +* JRuby 9.2.8.0 (2.5.3) 2019-08-12 a1ac7ff OpenJDK 64-Bit Server VM 11.0.4+11-post-Ubuntu-1ubuntu218.04.3 +jit [linux-x86_64] +* java openjdk version "11.0.4" 2019-07-16 +* julia version 1.2.0 +* clang version 7.0.0 +* Mono JIT compiler version 6.4.0.198 (tarball Tue Sep 24 01:21:28 UTC 2019) +* rock 0.9.11-head codename sapporo +* Felix version 2019.01.06 +* Q KDB+ 3.6 2019.04.02 Copyright (C) 1993-2019 Kx Systems +* perl 5, version 26, subversion 1 (v5.26.1) built for x86_64-linux-gnu-thread-multi +* The Glorious Glasgow Haskell Compilation System, version 8.6.5 * Tcl 8.6 -* jq version 1.3 -* Swift version 2.2-dev (LLVM ae2eb212e4, Clang ef4c02f431, Swift 634acb40a1) -* Kotlin version 1.0.3 (JRE 1.8.0_45-b14) -* PHP 7.0.9-1+deb.sury.org~trusty+1 (cli) ( NTS ) -* .Net Core 2.0.0 -* Elixir 1.2.0-rc.0 (a2860b3) Erlang/OTP 18 [erts-7.2] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false] -* Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio -* LuaJIT 2.0.2 -- Copyright (C) 2005-2013 Mike Pall. http://luajit.org/ -* truffleruby SNAPSHOT, like ruby 2.3.1 [linux-x86_64] -* MLton 20100608 (built Sun Oct 27 04:18:37 UTC 2013 on allspice) -* F# Compiler for F# 3.0 (Open Source Edition) -* OCaml 4.01.0 -* Racket v5.3.6. -* Chez Scheme Version 9.4 +* jq-1.5-1-a5b5cbe +* Swift version 5.1 (swift-5.1-RELEASE) +* Kotlin version 1.3.50-release-112 (JRE 11.0.4+11-post-Ubuntu-1ubuntu218.04.3) +* PHP 7.2.19-0ubuntu0.18.04.2 +* .NET Core SDK 3.0.100 +* Elixir 1.9.1 Erlang/OTP 22 [erts-10.5.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] +* Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio +* LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2017 Mike Pall. http://luajit.org/ +* truffleruby 19.2.0.1, like ruby 2.6.2, GraalVM CE Native [x86_64-linux] +* MLton 20130715 (built Fri Apr 28 06:06:34 UTC 2017 on lcy01-11) +* Microsoft (R) F# Compiler version 10.2.3 for F# 4.5 +* OCaml 4.07.0 +* Racket v6.11 +* Chez Scheme Version 9.5 diff --git a/base64/Base64Java.java b/base64/Base64Java.java index 64cc41ea..53afbc68 100644 --- a/base64/Base64Java.java +++ b/base64/Base64Java.java @@ -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"); } } diff --git a/base64/Test.kt b/base64/Test.kt index 32f3c19e..d89695f4 100644 --- a/base64/Test.kt +++ b/base64/Test.kt @@ -7,26 +7,32 @@ val enc = Base64.getEncoder(); val dec = Base64.getDecoder(); fun main(args: Array) { - 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}") -} \ No newline at end of file + val now = System.nanoTime() + println("decode: ${count2}, ${(now - t2) / 1e9}") + println("overall time: ${(now - t1) / 1e9}s") +} diff --git a/base64/base64.csproj b/base64/base64.csproj index 04b62d3a..4f26ee68 100644 --- a/base64/base64.csproj +++ b/base64/base64.csproj @@ -1,6 +1,6 @@ - netcoreapp2.0 + netcoreapp3.0 Exe diff --git a/base64/base64.rs/Cargo.lock b/base64/base64.rs/Cargo.lock index e0e8862b..31cba6ab 100644 --- a/base64/base64.rs/Cargo.lock +++ b/base64/base64.rs/Cargo.lock @@ -1,23 +1,24 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "base64" -version = "0.9.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "base64_rs" version = "0.0.1" dependencies = [ - "base64 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "byteorder" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -30,14 +31,9 @@ name = "redox_syscall" version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "safemem" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "time" -version = "0.1.39" +version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", @@ -65,12 +61,11 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum base64 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "229d032f1a99302697f10b27167ae6d03d49d032e6a8e2550e8d3fc13356d2b4" -"checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23" +"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" +"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" "checksum libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)" = "f54263ad99207254cf58b5f701ecb432c717445ea2ee8af387334bdd1a03fdff" "checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" -"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" -"checksum time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "a15375f1df02096fb3317256ce2cee6a1f42fc84ea5ad5fc8c421cfe40c73098" +"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/base64/base64.rs/Cargo.toml b/base64/base64.rs/Cargo.toml index b7922679..7b1f4c2f 100644 --- a/base64/base64.rs/Cargo.toml +++ b/base64/base64.rs/Cargo.toml @@ -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 diff --git a/base64/build.sh b/base64/build.sh old mode 100644 new mode 100755 index 07b44397..0fb4fb12 --- a/base64/build.sh +++ b/base64/build.sh @@ -1,9 +1,11 @@ +#!/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 @@ -11,7 +13,6 @@ 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 diff --git a/base64/run-ruby.sh b/base64/run-ruby.sh new file mode 100755 index 00000000..0bcd5b18 --- /dev/null +++ b/base64/run-ruby.sh @@ -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 diff --git a/base64/run.sh b/base64/run.sh old mode 100644 new mode 100755 index 738907c0..72269d38 --- a/base64/run.sh +++ b/base64/run.sh @@ -1,3 +1,5 @@ +#!/bin/sh + echo Crystal ../xtime.rb ./base64_cr echo Go @@ -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 @@ -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 diff --git a/base64/test-aklomp.c b/base64/test-aklomp.c index 771768ef..2c17acb0 100644 --- a/base64/test-aklomp.c +++ b/base64/test-aklomp.c @@ -1,5 +1,6 @@ #include "stdlib.h" #include "stdio.h" +#include #include "time.h" #include "libbase64.h" #include "../lib/config.h" @@ -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; diff --git a/base64/test-xs.pl b/base64/test-xs.pl index 465e1164..d5a549c5 100644 --- a/base64/test-xs.pl +++ b/base64/test-xs.pl @@ -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"; diff --git a/base64/test.c b/base64/test.c index 11a4b40b..f06383b6 100644 --- a/base64/test.c +++ b/base64/test.c @@ -2,6 +2,7 @@ #include "stdio.h" #include "time.h" #include +#include typedef unsigned int uint; const char* chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -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; diff --git a/base64/test.cr b/base64/test.cr index 0cbd51ac..a60afe06 100644 --- a/base64/test.cr +++ b/base64/test.cr @@ -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}" diff --git a/base64/test.cs b/base64/test.cs index b191f1e1..1a4afe9e 100644 --- a/base64/test.cs +++ b/base64/test.cs @@ -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++) { @@ -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(); @@ -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); } } } diff --git a/base64/test.jl b/base64/test.jl index 348e1dd0..b1e20beb 100644 --- a/base64/test.jl +++ b/base64/test.jl @@ -1,4 +1,4 @@ -using Codecs +using Base64 function main(tries) str_size = 10_000_000 @@ -8,8 +8,8 @@ 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") @@ -17,15 +17,15 @@ function main(tries) 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])") diff --git a/base64/test.js b/base64/test.js index 885c3949..2d625925 100644 --- a/base64/test.js +++ b/base64/test.js @@ -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; } @@ -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); diff --git a/base64/test.php b/base64/test.php index 9a0ce82c..c2c21e87 100644 --- a/base64/test.php +++ b/base64/test.php @@ -2,8 +2,7 @@ $STR_SIZE = 10000000; $TRIES = 100; -$str = ""; -for ($i = 0; $i < $STR_SIZE; $i++) $str .= "a"; +$str = str_repeat("a", $STR_SIZE); $str2 = ""; $s = 0; diff --git a/base64/test.pl b/base64/test.pl index 5cb5eb5b..5554d00b 100644 --- a/base64/test.pl +++ b/base64/test.pl @@ -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"; diff --git a/base64/test.scala b/base64/test.scala index 7615399b..98c4c7e9 100644 --- a/base64/test.scala +++ b/base64/test.scala @@ -2,23 +2,22 @@ object Base64 { val enc = java.util.Base64.getEncoder val dec = java.util.Base64.getDecoder - def encode(str: String) = enc.encodeToString(str.getBytes()) + def encode(str: Array[Byte]) = enc.encodeToString(str) def decode(str: String) = dec.decode(str) def main(args: Array[String]): Unit = { val STR_SIZE = 10000000 val TRIES = 100 - val str = "a" * STR_SIZE + val str = ("a" * STR_SIZE).getBytes() var str2 = "" - // warnup - for (_ <- 1 to 100) { - val str2 = encode("a" * 10000) - val str3 = decode(str2) + println("JIT warming up") + for (_ <- 1 to 5) { + decode(encode(str)) } - // - var t = System.nanoTime + println("run") + val t = System.nanoTime var s = 0 for (_ <- 1 to TRIES) { @@ -28,11 +27,13 @@ object Base64 { println("encode: " + s + ", " + (System.nanoTime - t)/1e9) s = 0 - t = System.nanoTime + val t1 = System.nanoTime for (_ <- 1 to TRIES) { val str3 = decode(str2) s += str3.length } - println("decode: " + s + ", " + (System.nanoTime - t)/1e9) + val now = System.nanoTime + println("decode: " + s + ", " + (now - t1) / 1e9) + println("overall time: " + (now - t) / 1e9 + "s") } } diff --git a/brainfuck/brainfuck.csproj b/brainfuck/brainfuck.csproj index 04b62d3a..4f26ee68 100644 --- a/brainfuck/brainfuck.csproj +++ b/brainfuck/brainfuck.csproj @@ -1,6 +1,6 @@ - netcoreapp2.0 + netcoreapp3.0 Exe diff --git a/brainfuck/brainfuck.flx b/brainfuck/brainfuck.flx index 12d1b563..8fecc169 100644 --- a/brainfuck/brainfuck.flx +++ b/brainfuck/brainfuck.flx @@ -2,20 +2,21 @@ include "stl/stl_vector"; include "stl/stl_map"; struct Tape { - tape: Stl_Vector[int]::stl_vector; + tape: varray[int]; pos: size; - proc inc() = { self*.tape.[self*.pos] = self*.tape.[self*.pos] + 1; } - proc dec() = { self*.tape.[self*.pos] = self*.tape.[self*.pos] - 1; } - proc advance() = { - self*.pos = self*.pos + 1; - if self*.pos.size >= self*.tape.len call push_back(self*.tape, 0); - } - proc devance() = { self*.pos = self*.pos - 1; } - fun get() => self.tape.[self.pos]; } +fun get(self: Tape) => get(self.tape, self.pos); +proc inc(self: &Tape) = { set(*self.tape, *self.pos, get(*self) + 1); } +proc dec(self: &Tape) = { set(*self.tape, *self.pos, get(*self) - 1); } +proc advance(self: &Tape) = { + self.pos <- *self.pos + 1; + if (*self.pos).size >= (*self.tape).len call push_back(*self.tape, 0); +} +proc devance(self: &Tape) = { self.pos <- *self.pos - 1; } + ctor Tape() = { - tape := #Stl_Vector[int]::create; + tape := varray[int] 1024.size; push_back(tape, 0); return Tape(tape, 0.size); } @@ -26,20 +27,20 @@ struct Program { } ctor Program(text: string) = { - bracket_map := #Stl_Map[int,int]::create; + var bracket_map = #Stl_Map[int,int]::create; pcode := #Stl_Vector[char]::create; - leftstack := #list[int]; + var leftstack = #list[int]; var pc = 0; valid := "[]<>+-,."; for chr in text do match find(valid, chr) with | Some p => push_back(pcode, chr); - match p with + match p.int with | 0 => leftstack = pc + leftstack; | 1 => - bracket_map.[leftstack.head] = pc; - bracket_map.[pc] = leftstack.head; + insert(bracket_map, leftstack.head, pc); + insert(bracket_map, pc, leftstack.head); leftstack = leftstack.tail; | _ => ; endmatch; @@ -55,13 +56,13 @@ proc run(p: Program) = { var pc = 0; while pc < p.pcode.len.int do match p.pcode.[pc.size].ord with - | 43 => #(&tape.inc); - | 45 => #(&tape.dec); - | 60 => #(&tape.devance); - | 62 => #(&tape.advance); - | 91 => if #(tape.get) == 0 do pc = p.bracket_map.[pc]; done - | 93 => if #(tape.get) != 0 do pc = p.bracket_map.[pc]; done - | 46 => print $ char $ #(tape.get); stdout.fflush; + | 43 => inc(&tape); + | 45 => dec(&tape); + | 60 => devance(&tape); + | 62 => advance(&tape); + | 91 => if get(tape) == 0 do pc = p.bracket_map.[pc]; done + | 93 => if get(tape) != 0 do pc = p.bracket_map.[pc]; done + | 46 => print $ char $ get(tape); stdout.fflush; endmatch; pc++; done diff --git a/brainfuck/brainfuck.jl b/brainfuck/brainfuck.jl index c83359df..9b71e69e 100644 --- a/brainfuck/brainfuck.jl +++ b/brainfuck/brainfuck.jl @@ -1,10 +1,8 @@ -type Tape +mutable struct Tape tape::Array{Int, 1} pos::Int - function Tape() - new(zeros(Int, 1), 1) - end + Tape() = new(zeros(Int, 1), 1) end inc(this::Tape) = (this.tape[this.pos] += 1) @@ -26,8 +24,8 @@ end validbfsymbol(x) = in(x, ['>', '<', '+', '-', '.', ',', '[', ']']) -type Program - code::ASCIIString +struct Program + code::String bracket_map::Dict{Int, Int} function Program(text) @@ -83,11 +81,13 @@ function main(text) run(Program(text)) end -println(STDERR, "warming") +println("JIT warming up") main(">++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++[>++++++++<-]>[-]<<>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++") -println(STDERR, "bench") -text = open(readall, ARGS[1]) +println("bench") +text = open(ARGS[1]) do file + read(file, String) +end x = @timed main(text) -println(STDERR, "Elapsed: $(x[2]), Allocated: $(x[3]), GC Time: $(x[4])") +println("Elapsed: $(x[2]), Allocated: $(x[3]), GC Time: $(x[4])") diff --git a/brainfuck/brainfuck.nim b/brainfuck/brainfuck.nim index 99dd378c..661b9721 100644 --- a/brainfuck/brainfuck.nim +++ b/brainfuck/brainfuck.nim @@ -1,7 +1,5 @@ import tables -import sequtils import os -import strutils type Tape = object diff --git a/brainfuck/brainfuck.scala b/brainfuck/brainfuck.scala index de7333a1..00e67178 100644 --- a/brainfuck/brainfuck.scala +++ b/brainfuck/brainfuck.scala @@ -15,8 +15,8 @@ class Program(text: String) { parse_code(text) - def parse_code(text: String) { - val leftstack = collection.mutable.ArrayStack.empty[Int] + def parse_code(text: String): Unit = { + val leftstack = collection.mutable.Stack.empty[Int] var pc = 0 for (ch <- text) ch match { diff --git a/brainfuck/build.sh b/brainfuck/build.sh old mode 100644 new mode 100755 index 49e0df79..2b6caebb --- a/brainfuck/build.sh +++ b/brainfuck/build.sh @@ -1,12 +1,14 @@ +#!/bin/sh + crystal build brainfuck.cr --release -o brainfuck_cr go build -o brainfuck_go brainfuck.go gccgo -O3 -g -o brainfuck_go_gccgo brainfuck.go g++ -O3 -o brainfuck_cpp brainfuck.cpp -scalac -optimize brainfuck.scala +scalac -opt:l:inline -deprecation brainfuck.scala rustc -C opt-level=3 brainfuck.rs -o brainfuck_rs dmd -ofbrainfuck_d -O -release -inline brainfuck.d gdc -o brainfuck_d_gdc -O3 -frelease -finline brainfuck.d -ldc2 -ofbrainfuck_d_ldc -O5 -release -inline brainfuck.d +ldc2 -ofbrainfuck_d_ldc -O5 -release brainfuck.d nim c -o:brainfuck_nim_clang -d:release --cc:clang --verbosity:0 brainfuck.nim nim c -o:brainfuck_nim_gcc -d:release --cc:gcc --verbosity:0 brainfuck.nim mcs -debug- -optimize+ brainfuck.cs diff --git a/brainfuck/run.sh b/brainfuck/run.sh old mode 100644 new mode 100755 index 47fa20aa..e90b3f79 --- a/brainfuck/run.sh +++ b/brainfuck/run.sh @@ -1,3 +1,5 @@ +#!/bin/sh + echo Crystal ../xtime.rb ./brainfuck_cr bench.b echo Go @@ -29,15 +31,13 @@ echo Julia echo Mono ../xtime.rb mono -O=all --gc=sgen brainfuck.exe bench.b echo .Net Core -../xtime.rb dotnet bin/Release/netcoreapp2.0/brainfuck.dll bench.b +../xtime.rb dotnet bin/Release/netcoreapp3.0/brainfuck.dll bench.b echo Python PyPy ../xtime.rb pypy brainfuck.py bench.b echo Python ../xtime.rb python brainfuck.py bench.b echo Ruby ../xtime.rb ruby brainfuck.rb bench.b -echo Ruby Topaz -../xtime.rb topaz brainfuck.rb bench.b echo OOC ../xtime.rb ./brainfuck_ooc bench.b echo Felix diff --git a/brainfuck/run2.sh b/brainfuck/run2.sh old mode 100644 new mode 100755 index 650965b2..8d9617f3 --- a/brainfuck/run2.sh +++ b/brainfuck/run2.sh @@ -1,3 +1,5 @@ +#!/bin/sh + echo Crystal ../xtime.rb ./brainfuck_cr mandel.b > /dev/null echo Go diff --git a/brainfuck2/bf.cpp b/brainfuck2/bf.cpp index a9ad9785..559e2cc6 100644 --- a/brainfuck2/bf.cpp +++ b/brainfuck2/bf.cpp @@ -29,7 +29,7 @@ class Tape { inline int get() { return tape[pos]; } inline void inc(int x) { tape[pos] += x; } - inline void move(int x) { pos += x; while (pos >= tape.size()) tape.push_back(0); } + inline void move(int x) { pos += x; while (pos >= tape.size()) tape.resize(2 * tape.size()); } }; class Program { @@ -97,4 +97,3 @@ int main(int argc, char** argv){ p.run(); return 0; } - diff --git a/brainfuck2/bf.cs b/brainfuck2/bf.cs index a93e6a38..8d42e65e 100644 --- a/brainfuck2/bf.cs +++ b/brainfuck2/bf.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.IO; using System.Linq; using System.Collections.Generic; @@ -38,7 +39,7 @@ class Program string code; int pos; Op[] ops; - + Program(string text) { code = text; @@ -48,7 +49,7 @@ class Program private Op[] parse() { List res = new List(); - while (pos < code.Length) { + while (pos < code.Length) { char c = code[pos]; pos++; switch (c) { @@ -82,8 +83,20 @@ private void _run(Op[] program, Tape tape) { static void Main(string[] args) { string text = File.ReadAllText(args[0]); + var stopWatch = new Stopwatch(); + Console.Error.WriteLine("JIT warming up"); + + stopWatch.Start(); + new Program(">++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++[>++++++++<-]>[-]<<>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++").run(); + stopWatch.Stop(); + Console.Error.WriteLine("time: " + stopWatch.ElapsedMilliseconds / 1e3 + "s"); + + Console.Error.WriteLine("run"); + stopWatch.Restart(); var p = new Program(text); p.run(); + stopWatch.Stop(); + Console.Error.WriteLine("time: " + stopWatch.ElapsedMilliseconds / 1e3 + "s"); } } } diff --git a/brainfuck2/bf.fs b/brainfuck2/bf.fs index c6941a96..4537f804 100644 --- a/brainfuck2/bf.fs +++ b/brainfuck2/bf.fs @@ -1,4 +1,5 @@ open System +open System.Diagnostics open System.IO type op = Inc of int | Move of int | Print | Loop of op list @@ -61,7 +62,21 @@ let main argv = let source = File.ReadAllLines filename |> String.concat "\n" + + let stopWatch = new Stopwatch() + Console.Error.WriteLine("JIT warming up") + + stopWatch.Start(); + let (_, ops) = parse(">++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++[>++++++++<-]>[-]<<>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++", []) + let _ = run ops { data = [| 0 |]; pos = 0 } + stopWatch.Stop() + Console.Error.WriteLine("time: {0}s", stopWatch.Elapsed.TotalSeconds) + + Console.Error.WriteLine("run") + stopWatch.Restart() let (_, ops) = parse(source, []) let _ = run ops { data = [| 0 |]; pos = 0 } + stopWatch.Stop() + Console.Error.WriteLine("time: {0}s", stopWatch.Elapsed.TotalSeconds) 0 | _ -> 1 diff --git a/brainfuck2/bf.go b/brainfuck2/bf.go index c1a520ea..3c3dc377 100644 --- a/brainfuck2/bf.go +++ b/brainfuck2/bf.go @@ -53,7 +53,6 @@ type Tape struct { func NewTape() *Tape { t := &Tape{pos: 0} t.tape = make([]int, 1) - t.Move(1) return t } @@ -96,6 +95,7 @@ func parse(si *StringIterator) []Op { case '[': op = NewOpLoop(LOOP, parse(si)) case ']': return res case byte(0): return res + default: continue } res = append(res, op) } diff --git a/brainfuck2/bf.java b/brainfuck2/bf.java index e9839a9b..8088f305 100644 --- a/brainfuck2/bf.java +++ b/brainfuck2/bf.java @@ -2,42 +2,44 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; -import java.util.Stack; -public class bf { +public final class bf { public enum OpT {INC, MOVE, PRINT, LOOP} - public static class Op { - public OpT op; - public int v; - public List loop; + public static final class Op { + private static final Op[] NO_LOOP_OPS = new Op[0]; - public Op(OpT _op, int _v) { op = _op; v = _v; loop = new ArrayList(); } - public Op(OpT _op, List _l) { op = _op; loop = _l; v = 0; } + public final OpT op; + public final int v; + public final Op[] loop; + + public Op(final OpT _op, final int _v) { op = _op; v = _v; loop = NO_LOOP_OPS; } + public Op(final OpT _op, final Op[] _l) { op = _op; loop = _l; v = 0; } } - public static class CharacterIterator { + public static final class CharacterIterator { private final String str; + private final int strLen; private int pos = 0; - public CharacterIterator(String str) { + public CharacterIterator(final String str) { this.str = str; + strLen = str.length(); } public boolean hasNext() { - return pos < str.length(); + return pos < strLen; } - public Character next() { + public char next() { return str.charAt(pos++); } } - public static class Tape { + public static final class Tape { private int[] tape; private int pos; @@ -49,31 +51,28 @@ public int get() { return tape[pos]; } - public void inc(int x) { + public void inc(final int x) { tape[pos] += x; } - public void move(int x) { + public void move(final int x) { pos += x; while ( pos >= tape.length ) { - int[] tape = new int[this.tape.length * 2]; - System.arraycopy( this.tape, 0, tape, 0, this.tape.length ); - this.tape = tape; + this.tape = Arrays.copyOf(this.tape, this.tape.length * 2); } - } } - public static class Program { - private List ops; + public static final class Program { + private final Op[] ops; - public Program(String code) { + public Program(final String code) { CharacterIterator it = new CharacterIterator(code); ops = parse(it); } - private List parse(CharacterIterator it) { - List res = new ArrayList(); + private Op[] parse(final CharacterIterator it) { + final List res = new ArrayList<>(); while (it.hasNext()) { switch( it.next() ) { case '+': @@ -95,41 +94,39 @@ private List parse(CharacterIterator it) { res.add(new Op(OpT.LOOP, parse(it))); break; case ']': - return res; + return res.toArray(new Op[res.size()]); } } - return res; + return res.toArray(new Op[res.size()]); } public void run() { _run(ops, new Tape()); } - private void _run(List program, Tape tape) { - for (Op op : program) { + private void _run(final Op[] program, final Tape tape) { + for (final Op op : program) switch (op.op) { case INC: tape.inc(op.v); break; case MOVE: tape.move(op.v); break; case LOOP: while (tape.get() > 0) _run(op.loop, tape); break; case PRINT: System.out.print( (char) tape.get() ); break; } - } } } - public static void main( String[] args ) throws IOException { - byte[] code = Files.readAllBytes( Paths.get( args[0] ) ); + public static void main( final String[] args ) throws IOException { + final byte[] code = Files.readAllBytes( Paths.get( args[0] ) ); long start_time = System.currentTimeMillis(); - System.err.println("warming"); + System.err.println("JIT warming up"); new Program(">++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++[>++++++++<-]>[-]<<>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++").run(); System.err.println("time: " + (System.currentTimeMillis()-start_time)/1e3+"s"); System.err.println("run"); start_time = System.currentTimeMillis(); - Program program = new Program(new String(code)); + final Program program = new Program(new String(code)); program.run(); System.err.println("time: " + (System.currentTimeMillis()-start_time)/1e3+"s"); } } - diff --git a/brainfuck2/bf.nim b/brainfuck2/bf.nim index 55fd76e2..d98baf47 100644 --- a/brainfuck2/bf.nim +++ b/brainfuck2/bf.nim @@ -1,7 +1,4 @@ -import tables -import sequtils import os -import strutils type OpT = enum @@ -87,7 +84,6 @@ proc runops(program: seq[Op], tape: var Tape) = of PRINT: write stdout, tape.get.chr flushFile(stdout) - else: discard proc run(self: Program) = var tape = newTape() diff --git a/brainfuck2/bf.scala b/brainfuck2/bf.scala index 6f359877..817a5967 100644 --- a/brainfuck2/bf.scala +++ b/brainfuck2/bf.scala @@ -1,56 +1,54 @@ -abstract class Op +import scala.collection.mutable.ArrayBuffer + +sealed abstract class Op case class Inc(v: Int) extends Op case class Move(v: Int) extends Op -case class Print() extends Op case class Loop(loop: Array[Op]) extends Op -case class Nop() extends Op +case object Print extends Op class Tape() { - private var tape = Array(0) - private var pos = 0 + private var tape: Array[Int] = Array(0) + private var pos: Int = 0 def get = tape(pos) def inc(x: Int) = tape(pos) += x def move(x: Int) = { pos += x - while (pos >= tape.length) { tape :+= 0 } + while (pos >= tape.length) { + tape = Array.copyOf(tape, tape.length * 2) + } } } class Program(text: String) { - var ops = parse(text.iterator) + val ops: Array[Op] = parse(text.iterator) def parse(iterator: Iterator[Char]) : Array[Op] = { - var res = Array[Op]() + val res = ArrayBuffer[Op]() while (iterator.hasNext) { - val op = iterator.next() match { - case '+' => new Inc(1) - case '-' => new Inc(-1) - case '>' => new Move(1) - case '<' => new Move(-1) - case '.' => new Print() - case '[' => new Loop(parse(iterator)) - case ']' => return res - case _ => new Nop() - } - - op match { - case Nop() => () - case _ => res :+= op + iterator.next() match { + case '+' => res += Inc(1) + case '-' => res += Inc(-1) + case '>' => res += Move(1) + case '<' => res += Move(-1) + case '.' => res += Print + case '[' => res += Loop(parse(iterator)) + case ']' => return res.toArray + case _ => } } - res + res.toArray } def run = _run(ops, new Tape()) - def _run(program: Array[Op], tape: Tape) { + def _run(program: Array[Op], tape: Tape): Unit = { for (op <- program) op match { case Inc(x) => tape.inc(x) case Move(x) => tape.move(x) case Loop(loop) => while (tape.get > 0) _run(loop, tape) - case Print() => print(tape.get.toChar) + case Print => print(tape.get.toChar) } } @@ -67,8 +65,8 @@ object BrainFuck { def main(args: Array[String]): Unit = { val text = scala.io.Source.fromFile(args(0)).mkString - //warmup - System.err.print("warmup\n") + // JIT warming up + System.err.print("JIT warming up\n") time { new Program(">++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++[>++++++++<-]>[-]<<>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++").run } diff --git a/brainfuck2/bf2.kt b/brainfuck2/bf2.kt index 50d9badd..06347a2e 100644 --- a/brainfuck2/bf2.kt +++ b/brainfuck2/bf2.kt @@ -1,6 +1,7 @@ import java.io.IOException import java.nio.file.Files import java.nio.file.Paths +import java.util.Arrays sealed class Op() { class Inc(val v: Int): Op() @@ -24,9 +25,7 @@ class Tape { fun move(x: Int) { pos += x while (pos >= tape.size) { - val tape = IntArray(this.tape.size * 2) - System.arraycopy(this.tape, 0, tape, 0, this.tape.size) - this.tape = tape + this.tape = Arrays.copyOf(this.tape, this.tape.size * 2) } } } @@ -76,7 +75,7 @@ class Program(code: String) { fun warming() { val WARM_PROGRAM = ">++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++[>++++++++<-]>[-]<<>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[>++++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++" - System.err.println("warming") + System.err.println("JIT warming up") val start_time = System.currentTimeMillis() Program(WARM_PROGRAM).run() System.err.println("time: ${(System.currentTimeMillis() - start_time) / 1e3}s") diff --git a/brainfuck2/brainfuck2.csproj b/brainfuck2/brainfuck2.csproj index 04b62d3a..4f26ee68 100644 --- a/brainfuck2/brainfuck2.csproj +++ b/brainfuck2/brainfuck2.csproj @@ -1,6 +1,6 @@ - netcoreapp2.0 + netcoreapp3.0 Exe diff --git a/brainfuck2/build.sh b/brainfuck2/build.sh old mode 100644 new mode 100755 index 300d2a4f..c8b75d11 --- a/brainfuck2/build.sh +++ b/brainfuck2/build.sh @@ -1,7 +1,9 @@ +#!/bin/sh + crystal build bf.cr --release -o bin_cr --no-debug g++ -flto -O3 -o bin_cpp bf.cpp rustc -C opt-level=3 -C lto bf.rs -o bin_rs -scalac -optimize bf.scala +scalac -opt:l:inline -deprecation bf.scala mcs -debug- -optimize+ bf.cs dotnet build -c Release javac bf.java @@ -13,8 +15,8 @@ gdc -o bin_d_gdc -O3 -frelease -finline bf.d ldc2 -ofbin_d_ldc -O5 -release bf.d nim c -o:bin_nim_clang -d:release --cc:clang --verbosity:0 bf.nim nim c -o:bin_nim_gcc -d:release --cc:gcc --verbosity:0 bf.nim -stack ghc -- -O2 bf.hs -o bin_hs -stack ghc -- -O2 bf-marray.hs -o bin_hs_marray +stack ghc -- -O2 -fforce-recomp bf.hs -o bin_hs +stack ghc -- -O2 -fforce-recomp bf-marray.hs -o bin_hs_marray ocamlopt bf.ml -o bin_ocaml fsharpc bf.fs -o bin_fs.exe mlton -output bin_sml bf.sml diff --git a/brainfuck2/run-ruby.sh b/brainfuck2/run-ruby.sh new file mode 100755 index 00000000..b0509a42 --- /dev/null +++ b/brainfuck2/run-ruby.sh @@ -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 bf.rb bench.b +done diff --git a/brainfuck2/run.sh b/brainfuck2/run.sh old mode 100644 new mode 100755 index be313cc6..d868020f --- a/brainfuck2/run.sh +++ b/brainfuck2/run.sh @@ -1,3 +1,5 @@ +#!/bin/sh + echo Cpp ../xtime.rb ./bin_cpp bench.b echo Crystal @@ -13,7 +15,7 @@ echo Kotlin echo C# Mono ../xtime.rb mono -O=all --gc=sgen bf.exe bench.b echo C# .Net Core -../xtime.rb dotnet bin/Release/netcoreapp2.0/brainfuck2.dll bench.b +../xtime.rb dotnet bin/Release/netcoreapp3.0/brainfuck2.dll bench.b echo Elixir ../xtime.rb elixir bf.ex bench.b echo F# Mono @@ -42,8 +44,6 @@ echo Nim Clang ../xtime.rb ./bin_nim_clang bench.b echo OCaml ../xtime.rb ./bin_ocaml bench.b -echo Ruby Topaz -../xtime.rb topaz bf.rb bench.b echo Python PyPy ../xtime.rb pypy bf.py bench.b echo Perl @@ -56,13 +56,13 @@ echo Python3 ../xtime.rb python3 bf3.py bench.b echo Standard ML MLton ../xtime.rb ./bin_sml bench.b -echo Lua 5.1 -../xtime.rb lua5.1 bf.lua bench.b +echo Lua 5.3 +../xtime.rb lua5.3 bf.lua bench.b echo LuaJIT ../xtime.rb luajit bf.lua bench.b -echo Tcl (FP) +echo "Tcl (FP)" ../xtime.rb tclsh bf.tcl bench.b -echo Tcl (OO) +echo "Tcl (OO)" ../xtime.rb tclsh bf_oo.tcl bench.b echo Racket ../xtime.rb racket bf.rkt bench.b diff --git a/brainfuck2/run2.sh b/brainfuck2/run2.sh old mode 100644 new mode 100755 index ee2ea2e3..8e6c8e82 --- a/brainfuck2/run2.sh +++ b/brainfuck2/run2.sh @@ -1,3 +1,5 @@ +#!/bin/sh + echo Cpp ../xtime.rb ./bin_cpp mandel.b > /dev/null echo D @@ -35,11 +37,9 @@ echo Javascript Node echo C# Mono ../xtime.rb mono -O=all --gc=sgen bf.exe mandel.b > /dev/null echo C# .Net Core -../xtime.rb dotnet bin/Release/netcoreapp2.0/brainfuck2.dll mandel.b > /dev/null +../xtime.rb dotnet bin/Release/netcoreapp3.0/brainfuck2.dll mandel.b > /dev/null echo Python PyPy ../xtime.rb pypy bf.py mandel.b > /dev/null -echo Ruby Topaz -../xtime.rb topaz bf.rb mandel.b > /dev/null echo Standard ML MLton ../xtime.rb ./bin_sml mandel.b > /dev/null echo LuaJIT diff --git a/havlak/build.sh b/havlak/build.sh old mode 100644 new mode 100755 index 75602f29..18adff56 --- a/havlak/build.sh +++ b/havlak/build.sh @@ -1,8 +1,10 @@ +#!/bin/sh + crystal build havlak.cr --release -o havlak_cr --no-debug go build -o havlak_go havlak.go gccgo -O3 -g -o havlak_go_gccgo havlak.go g++ -O3 -o havlak_cpp havlak.cpp -scalac -optimize havlak.scala +scalac -opt:l:inline -deprecation havlak.scala dmd -ofhavlak_d -O -release -inline havlak.d gdc -o havlak_d_gdc -O3 -frelease -finline havlak.d ldc2 -ofhavlak_d_ldc -O5 -release havlak.d diff --git a/havlak/havlak.csproj b/havlak/havlak.csproj index 04b62d3a..4f26ee68 100644 --- a/havlak/havlak.csproj +++ b/havlak/havlak.csproj @@ -1,6 +1,6 @@ - netcoreapp2.0 + netcoreapp3.0 Exe diff --git a/havlak/havlak.go b/havlak/havlak.go index 478a7408..e92ffa09 100644 --- a/havlak/havlak.go +++ b/havlak/havlak.go @@ -42,16 +42,13 @@ func NewCFG() *CFG { } func (cfg *CFG) CreateNode(node int) *BasicBlock { - if bblock := cfg.Bb[node]; bblock != nil { - return bblock - } - bblock := NewBasicBlock(node) - cfg.Bb[node] = bblock - - if len(cfg.Bb) == 1 { - cfg.StartNode = bblock + bblock := cfg.Bb[node] + if bblock == nil { + bblock = NewBasicBlock(node) + cfg.Bb[node] = bblock } + cfg.StartNode = bblock return bblock } @@ -73,7 +70,7 @@ func NewBasicBlockEdge(cfg *CFG, from int, to int) *BasicBlockEdge { self.To = cfg.CreateNode(to) self.From = cfg.CreateNode(from) - self.From.OutEdges = append(self.From.OutEdges,self.To) + self.From.OutEdges = append(self.From.OutEdges, self.To) self.To.InEdges = append(self.To.InEdges, self.From) return self diff --git a/havlak/havlak.nim b/havlak/havlak.nim index f90b47b3..b56985c7 100644 --- a/havlak/havlak.nim +++ b/havlak/havlak.nim @@ -1,5 +1,4 @@ import tables -import sequtils import sets type @@ -49,12 +48,13 @@ proc addEdge(self: var Cfg, edge: BasicBlockEdge) = proc getNumNodes(self: Cfg): int = self.basicBlockMap.len -proc NewBasicBlockEdge(cfg: var Cfg, fromName: int, toName: int): BasicBlockEdge = - result.fr = cfg.createNode(fromName) - result.to = cfg.createNode(toName) - result.fr.outEdges.add(result.to) - result.to.inEdges.add(result.fr) - cfg.addEdge(result) +proc NewBasicBlockEdge(cfg: var Cfg, fromName: int, toName: int) = + var newEdge = BasicBlockEdge() + newEdge.fr = cfg.createNode(fromName) + newEdge.to = cfg.createNode(toName) + newEdge.fr.outEdges.add(newEdge.to) + newEdge.to.inEdges.add(newEdge.fr) + cfg.addEdge(newEdge) type SimpleLoop = object @@ -159,13 +159,11 @@ proc union(self: ref UnionFindNode, unionFindNode: ref UnionFindNode) = const - BB_TOP = 0 # uninitialized BB_NONHEADER = 1 # a regular BB BB_REDUCIBLE = 2 # reducible loop BB_SELF = 3 # single BB loop BB_IRREDUCIBLE = 4 # irreducible loop BB_DEAD = 5 # a dead BB - BB_LAST = 6 # Sentinel # # Marker for uninitialized nodes. UNVISITED = -1 @@ -211,7 +209,7 @@ proc findLoops(self: var HavlakLoopFinder): int = var nodes = newSeq[ref UnionFindNode]() for i in 1..size: - nonBackPreds.add initSet[int](1) + nonBackPreds.add initHashSet[int](1) backPreds.add newSeq[int]() nodes.add NewUnionFindNode() @@ -221,7 +219,7 @@ proc findLoops(self: var HavlakLoopFinder): int = # - unreached BB's are marked as dead. # for v in self.cfg.basicBlockMap.values: number[v] = UNVISITED - var res = dfs(startNode, nodes, number, last, 0) + discard dfs(startNode, nodes, number, last, 0) # Step b: # - iterate over all nodes. @@ -233,7 +231,7 @@ proc findLoops(self: var HavlakLoopFinder): int = # - the list of backedges (backPreds) or # - the list of non-backedges (nonBackPreds) # - for w in 0 .. b) a else b - def calculateNestingLevelRec(loop : SimpleLoop, depth : Int) { + def calculateNestingLevelRec(loop : SimpleLoop, depth : Int): Unit = { loop.depthLevel_=(depth) for (liter <- loop.children) { calculateNestingLevelRec(liter, depth+1) @@ -603,7 +602,7 @@ object LoopTesterApp { footer } - def main(args: Array[String]) { + def main(args: Array[String]): Unit = { println("Welcome to LoopTesterApp, Scala edition") println("Constructing Simple CFG...") diff --git a/havlak/run.sh b/havlak/run.sh old mode 100644 new mode 100755 index 8dc2d1ee..0e0ea02b --- a/havlak/run.sh +++ b/havlak/run.sh @@ -1,3 +1,5 @@ +#!/bin/sh + echo Cpp ../xtime.rb ./havlak_cpp echo Go @@ -25,4 +27,4 @@ echo Python echo Mono ../xtime.rb mono -O=all --gc=sgen havlak.exe echo C# .Net Core -../xtime.rb dotnet bin/Release/netcoreapp2.0/havlak.dll +../xtime.rb dotnet bin/Release/netcoreapp3.0/havlak.dll diff --git a/json/build.sh b/json/build.sh old mode 100644 new mode 100755 index 96a41bac..ab54cd94 --- a/json/build.sh +++ b/json/build.sh @@ -1,3 +1,5 @@ +#!/bin/sh + if [ ! -f 1.json ]; then ruby generate_json.rb fi @@ -34,8 +36,8 @@ if [ ! -d gason ]; then fi g++ -std=c++11 test_gason.cpp -I gason/src/ gason/src/gason.cpp -o json_gason_cpp -O3 -g++ -O3 test_libjson.cpp -o json_libjson_cpp -ljson -julia -e 'Pkg.add("JSON")' +g++ -O3 test_libjson.cpp -o json_libjson_cpp -ljson-c +julia -e 'using Pkg; Pkg.add("JSON")' # mono nuget install Newtonsoft.Json cp Newtonsoft.Json.*/lib/net45/Newtonsoft.Json.dll . @@ -52,7 +54,7 @@ wget -qO - https://cpanmin.us | perl - -L perllib Cpanel::JSON::XS JSON::Tiny Fi cd json-hs; make; cd .. # clojure -cd json-clj; lein uberjar; cd ..; cp json-clj/test.jar ./ +cd json-clj; lein uberjar; cd ..; cp json-clj/target/test.jar ./ # python/python3/pypy pip install ujson @@ -62,4 +64,4 @@ pip3 install ujson cd json-java; mvn clean install; cp target/java-json-1.5-jar-with-dependencies.jar ../java-json.jar; cd .. #scala -cd json-scala; sbt clean assembly; cp target/scala-2.12/benchmark-json-scala-assembly-1.1.jar ../scala-json.jar; cd .. +cd json-scala; sbt clean assembly; cp target/scala-2.13/benchmark-json-scala-assembly-1.1.jar ../scala-json.jar; cd .. diff --git a/json/json-clj/src/json.clj b/json/json-clj/src/json.clj index 5fa92bc5..daad947d 100644 --- a/json/json-clj/src/json.clj +++ b/json/json-clj/src/json.clj @@ -4,10 +4,11 @@ (:gen-class)) (defn -main [] - (time - (let [data (:coordinates (parse-stream (reader "./1.json") true)) + (dotimes [i 5] + (time + (let [data (:coordinates (parse-stream (reader "./1.json") true)) len (count data)] - (loop [sx 0.0 sy 0.0 sz 0.0 [coord & coords] data] - (if-let [{:keys [x y z]} coord] - (recur (+ sx x) (+ sy y) (+ sz z) coords) - (println (/ sx len) (/ sy len) (/ sz len))))))) + (loop [sx 0.0 sy 0.0 sz 0.0 [coord & coords] data] + (if-let [{:keys [x y z]} coord] + (recur (+ sx x) (+ sy y) (+ sz z) coords) + (println (/ sx len) (/ sy len) (/ sz len)))))))) diff --git a/json/json-hs/stack.yaml b/json/json-hs/stack.yaml index ed95107c..c32f5075 100644 --- a/json/json-hs/stack.yaml +++ b/json/json-hs/stack.yaml @@ -1,7 +1,7 @@ # For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md # Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) -resolver: lts-3.7 +resolver: lts-14.7 # Local packages, usually specified by relative directory name packages: @@ -9,7 +9,7 @@ packages: # Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) extra-deps: -- json-stream-0.3.2.2 +- json-stream-0.4.2.2 # Override default flag values for local packages and extra-deps flags: {} diff --git a/json/json-hs/stack.yaml.lock b/json/json-hs/stack.yaml.lock new file mode 100644 index 00000000..df08ff87 --- /dev/null +++ b/json/json-hs/stack.yaml.lock @@ -0,0 +1,19 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: +- completed: + hackage: json-stream-0.4.2.2@sha256:7efd3e88d160e9f844ef4d6499d63831eba9b89f348ed3e4ac7eb8a362a713d0,4724 + pantry-tree: + size: 2055 + sha256: 0713e3098f827c1183de839693f94ec5e3e1d1d6698e36dc2c1ba5780d878918 + original: + hackage: json-stream-0.4.2.2 +snapshots: +- completed: + size: 523700 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/14/7.yaml + sha256: 8e3f3c894be74d71fa4bf085e0a8baae7e4d7622d07ea31a52736b80f8b9bb1a + original: lts-14.7 diff --git a/json/json-java/src/main/java/bench/TestJava.java b/json/json-java/src/main/java/bench/TestJava.java index e818f894..6cbe94d2 100644 --- a/json/json-java/src/main/java/bench/TestJava.java +++ b/json/json-java/src/main/java/bench/TestJava.java @@ -34,7 +34,7 @@ public static void parse(String filename) throws IOException { } public static void main(String[] args) throws IOException { - // warming + // JIT warming up for(int i = 0; i < 5; i++) { parse("1.json"); } diff --git a/json/json-scala/build.sbt b/json/json-scala/build.sbt index f7f210d0..566e2598 100644 --- a/json/json-scala/build.sbt +++ b/json/json-scala/build.sbt @@ -2,6 +2,6 @@ name := "benchmark-json-scala" version := "1.1" -scalaVersion := "2.12.5" +scalaVersion := "2.13.0" -libraryDependencies += "com.dslplatform" %% "dsl-json-scala" % "1.7.1" \ No newline at end of file +libraryDependencies += "com.dslplatform" %% "dsl-json-scala" % "1.9.3" diff --git a/json/json-scala/project/build.properties b/json/json-scala/project/build.properties index d638b4f3..218101f1 100644 --- a/json/json-scala/project/build.properties +++ b/json/json-scala/project/build.properties @@ -1 +1 @@ -sbt.version = 0.13.8 \ No newline at end of file +sbt.version = 1.3.2 diff --git a/json/json-scala/project/plugins.sbt b/json/json-scala/project/plugins.sbt index 03445dee..0e228342 100644 --- a/json/json-scala/project/plugins.sbt +++ b/json/json-scala/project/plugins.sbt @@ -1,3 +1,3 @@ logLevel := Level.Warn -addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.2") \ No newline at end of file +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10") diff --git a/json/json-scala/src/main/scala/JsonTest.scala b/json/json-scala/src/main/scala/JsonTest.scala index ef7cfaa6..eb2cbb03 100644 --- a/json/json-scala/src/main/scala/JsonTest.scala +++ b/json/json-scala/src/main/scala/JsonTest.scala @@ -19,7 +19,7 @@ object JsonTest { val start_time = System.nanoTime val settings = new DslJson.Settings[Any]().doublePrecision(JsonReader.DoublePrecision.LOW).`with`(new ConfigureScala) - val dslJson = new DslJson[Any](settings) + implicit val dslJson = new DslJson[Any](settings) val fs = new FileInputStream("1.json") val root = dslJson.decode[Root](fs) diff --git a/json/json.csproj b/json/json.csproj index 09ff615c..6e9b6029 100644 --- a/json/json.csproj +++ b/json/json.csproj @@ -1,6 +1,6 @@ - netcoreapp2.0 + netcoreapp3.0 Exe diff --git a/json/json.rs/Cargo.lock b/json/json.rs/Cargo.lock index 7aef1874..65aa57d7 100644 --- a/json/json.rs/Cargo.lock +++ b/json/json.rs/Cargo.lock @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "dtoa" version = "0.4.2" diff --git a/json/run-ruby.sh b/json/run-ruby.sh new file mode 100755 index 00000000..0bcd5b18 --- /dev/null +++ b/json/run-ruby.sh @@ -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 diff --git a/json/run.sh b/json/run.sh index 9c920dff..442f360c 100755 --- a/json/run.sh +++ b/json/run.sh @@ -1,3 +1,5 @@ +#!/bin/sh + echo Crystal ../xtime.rb ./json_cr echo Crystal Pull @@ -53,7 +55,7 @@ echo Julia echo Mono ../xtime.rb mono -O=all --gc=sgen test.exe echo C# .Net Core -../xtime.rb dotnet bin/Release/netcoreapp2.0/json.dll +../xtime.rb dotnet bin/Release/netcoreapp3.0/json.dll echo Ruby ../xtime.rb ruby test.rb echo Ruby YAJL diff --git a/json/test.cs b/json/test.cs index ca17e902..1e6776ab 100644 --- a/json/test.cs +++ b/json/test.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.IO; using System.Linq; using Newtonsoft.Json.Linq; @@ -21,8 +22,9 @@ public class Root public List Coordinates { get; set; } } - static void Main(string[] args) + static void ParseJson() { + var sw = Stopwatch.StartNew(); var text = File.ReadAllText("./1.json"); var root = JsonConvert.DeserializeObject(text); @@ -41,6 +43,16 @@ static void Main(string[] args) }; Console.WriteLine("{0}\n{1}\n{2}", x/count, y/count, z/count); + sw.Stop(); + Console.WriteLine("time: {0}s", sw.Elapsed.TotalSeconds); + } + + static void Main(string[] args) + { + for (int i = 0; i < 5; i++) + { + ParseJson(); + } } } } diff --git a/json/test.jl b/json/test.jl index e0deff7b..f198a77d 100644 --- a/json/test.jl +++ b/json/test.jl @@ -1,7 +1,9 @@ import JSON function main() - text = open(readall, "1.json") + text = open("1.json") do file + read(file, String) + end jobj = JSON.parse(text) coordinates = jobj["coordinates"] len = length(coordinates) @@ -20,7 +22,9 @@ end function test() x = @timed main() - println(STDERR, "Elapsed: $(x[2]), Allocated: $(x[3]), GC Time: $(x[4])") + println("Elapsed: $(x[2]), Allocated: $(x[3]), GC Time: $(x[4])") end -test() +for i in 1:5 + test() +end diff --git a/json/test_libjson.cpp b/json/test_libjson.cpp index 78cb3343..be90e466 100644 --- a/json/test_libjson.cpp +++ b/json/test_libjson.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -21,19 +21,26 @@ int main() { read_file("./1.json", ss); string text = ss.str(); json_object* jobj = json_tokener_parse(text.c_str()); - json_object* coordinates = json_object_object_get(jobj, "coordinates"); - int len = json_object_array_length(coordinates); - double x = 0, y = 0, z = 0; + json_object* coordinates; + if (json_object_object_get_ex(jobj, "coordinates", &coordinates)) { + int len = json_object_array_length(coordinates); + double x = 0, y = 0, z = 0; - for (int i = 0; i < len; i++) { - json_object* coord = json_object_array_get_idx(coordinates, i); - x += json_object_get_double(json_object_object_get(coord, "x")); - y += json_object_get_double(json_object_object_get(coord, "y")); - z += json_object_get_double(json_object_object_get(coord, "z")); - } + for (int i = 0; i < len; i++) { + json_object* coord = json_object_array_get_idx(coordinates, i); + json_object *xobj, *yobj, *zobj; + if (json_object_object_get_ex(coord, "x", &xobj) && + json_object_object_get_ex(coord, "y", &yobj) && + json_object_object_get_ex(coord, "z", &zobj)) { + x += json_object_get_double(xobj); + y += json_object_get_double(yobj); + z += json_object_get_double(zobj); + } + } - printf("%.8f\n", x / len); - printf("%.8f\n", y / len); - printf("%.8f\n", z / len); + printf("%.8f\n", x / len); + printf("%.8f\n", y / len); + printf("%.8f\n", z / len); + } } diff --git a/matmul/build.sh b/matmul/build.sh old mode 100644 new mode 100755 index 5551dbfb..b7a0ba01 --- a/matmul/build.sh +++ b/matmul/build.sh @@ -1,13 +1,15 @@ +#!/bin/sh + crystal build matmul.cr --release -o matmul_cr --no-debug go build -o matmul_go matmul.go gccgo -O3 -g -o matmul_go_gccgo matmul.go gcc -O3 -o matmul_c matmul.c -scalac -optimize matmul.scala +scalac -opt:l:inline -deprecation matmul.scala rustc -C opt-level=3 -C lto matmul.rs -o matmul_rs dmd -ofmatmul_d -O -release -inline matmul.d gdc -o matmul_d_gdc -O3 -frelease -finline matmul.d ldc2 -ofmatmul_d_ldc -O5 -release matmul.d -dub build --build=release --single matmul_d_mir.d --compiler=ldmd2 +dub build --build=release --single matmul_d_lubeck.d --compiler=ldc2 nim c -o:matmul_nim_gcc --cc:gcc -d:release --verbosity:0 matmul.nim nim c -o:matmul_nim_clang --cc:clang -d:release --verbosity:0 matmul.nim javac matmul.java diff --git a/matmul/matmul-native.jl b/matmul/matmul-native.jl index 9107b18f..68131e2e 100644 --- a/matmul/matmul-native.jl +++ b/matmul/matmul-native.jl @@ -20,12 +20,12 @@ function test() n = parse(Int, ARGS[1]) end - println(STDERR, "warming") + println("JIT warming up") main(200) - println(STDERR, "bench") + println("bench") x = @timed main(n) - println(STDERR, "Elapsed: $(x[2]), Allocated: $(x[3]), GC Time: $(x[4])") + println("Elapsed: $(x[2]), Allocated: $(x[3]), GC Time: $(x[4])") end test() diff --git a/matmul/matmul.cr b/matmul/matmul.cr index 9c5e429f..5e6edfdf 100644 --- a/matmul/matmul.cr +++ b/matmul/matmul.cr @@ -36,8 +36,8 @@ def matgen(n) end n = (ARGV[0]? || 100).to_i -n = n / 2 * 2 +n = n >> 1 << 1 a = matgen(n) b = matgen(n) c = matmul(a, b) -puts c[n / 2][n / 2] +puts c[n >> 1][n >> 1] diff --git a/matmul/matmul.cs b/matmul/matmul.cs index 1845a5b1..fb0d1786 100644 --- a/matmul/matmul.cs +++ b/matmul/matmul.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; namespace test { @@ -41,12 +42,21 @@ static void Main(string[] args) { int n = 100; if (args.Length >= 1) n = int.Parse(args[0]) / 2 * 2; - Console.WriteLine("N = {0}", n); + double[,] a, b, x; + a = MatGen(500); + b = MatGen(500); + x = MatMul(ref a, ref b); + Console.WriteLine("JIT warming up: {0}", x[1, 1]); + + Console.WriteLine("N = {0}", n); + var sw = Stopwatch.StartNew(); a = MatGen(n); b = MatGen(n); x = MatMul(ref a, ref b); + sw.Stop(); Console.WriteLine(x[n/2,n/2]); + Console.WriteLine("time: {0}s", sw.Elapsed.TotalSeconds); } } } diff --git a/matmul/matmul.csproj b/matmul/matmul.csproj index 04b62d3a..4f26ee68 100644 --- a/matmul/matmul.csproj +++ b/matmul/matmul.csproj @@ -1,6 +1,6 @@ - netcoreapp2.0 + netcoreapp3.0 Exe diff --git a/matmul/matmul.d b/matmul/matmul.d index e2be4cc4..2f67e5ec 100644 --- a/matmul/matmul.d +++ b/matmul/matmul.d @@ -4,11 +4,21 @@ import std.numeric, std.stdio, std.string, std.conv; double[][] matGen(in int n) { - double tmp = 1.0 / n / n; + auto len = n * n; + double tmp = 1.0 / len; auto a = new double[][](n, n); - foreach (int i, row; a) - foreach (int j, ref x; row) - x = tmp * (i - j) * (i + j); + size_t i; + foreach (ref row; a) + { + sizediff_t u = i, v = i; + foreach (ref x; row) + { + x = tmp * (u * v); + u--; + v++; + } + i++; + } return a; } diff --git a/matmul/matmul.java b/matmul/matmul.java index a0c1ca7f..ca988dfd 100644 --- a/matmul/matmul.java +++ b/matmul/matmul.java @@ -36,7 +36,7 @@ public static void main(String[] args) { matmul m = new matmul(); double[][] t = m.matmul(m.matgen(500), m.matgen(500)); - System.out.println("warnup: " + t[1][1]); + System.out.println("JIT warming up: " + t[1][1]); long start_time = System.currentTimeMillis(); diff --git a/matmul/matmul.jl b/matmul/matmul.jl index cd108aab..1cdc1704 100644 --- a/matmul/matmul.jl +++ b/matmul/matmul.jl @@ -46,12 +46,12 @@ function test() n = parse(Int, ARGS[1]) end - println(STDERR, "warming") + println("JIT warming up") main(200) - println(STDERR, "bench") + println("bench") x = @timed main(n) - println(STDERR, "Elapsed: $(x[2]), Allocated: $(x[3]), GC Time: $(x[4])") + println("Elapsed: $(x[2]), Allocated: $(x[3]), GC Time: $(x[4])") end test() diff --git a/matmul/matmul.kt b/matmul/matmul.kt index bdbe2ff7..791986b5 100644 --- a/matmul/matmul.kt +++ b/matmul/matmul.kt @@ -50,7 +50,7 @@ fun main(args: Array) { else { 25 } val t = matmul(matgen(500), matgen(500)) - println("warmup: ${t[1][1]}") + println("JIT warming up: ${t[1][1]}") val start_time = System.currentTimeMillis() val a = matgen(n) diff --git a/matmul/matmul.nim b/matmul/matmul.nim index f09fdd06..12993479 100644 --- a/matmul/matmul.nim +++ b/matmul/matmul.nim @@ -1,20 +1,19 @@ import os, strutils type - Matrix = seq[seq[float64]] + Matrix = seq[seq[float]] proc newmat(x: int, y: int): Matrix = - result = @[] - for i in 0..x-1: - result.add(@[]) - for j in 0..y-1: result[i].add(0.0) + result.setLen x + for i in 0 ..< x: + result[i] = newSeq[float](y) proc matgen(n: int): Matrix = result = newmat(n, n) - let tmp = 1.0'f32 / float64(n) / float64(n) - for i in 0 .. [[Double]]{ - var a = [[Double]](count: n, repeatedValue: [Double](count: n, repeatedValue : 0)) +func matgen(_ n: Int) -> [[Double]]{ + var a = Array(repeating: Array(repeating: 0, count: n), count: n) let divideBy = Double(n) let tmp = 1.0 / divideBy / divideBy for i in 0.. [[Double]]{ return a } -func matmul(a : [[Double]], b : [[Double]]) ->[[Double]] { +func matmul(_ a : [[Double]], b : [[Double]]) ->[[Double]] { let m = a.count let n = a[0].count let p = b[0].count - var x = [[Double]](count: m, repeatedValue : [Double](count: p, repeatedValue : 0)) - var c = [[Double]](count: p, repeatedValue : [Double](count : n, repeatedValue: 0)) + var x = Array(repeating: Array(repeating: 0, count: p), count: m) + var c = Array(repeating: Array(repeating: 0, count: n), count: p) for i in 0..[[Double]] { return x } - - var n = 100; -if Process.argc != 2 { +if CommandLine.argc != 2 { print("Usage: ./matmulswift {arg}") exit(1) } -let end = Int(String.fromCString(Process.arguments[1])!)! +let end = Int(CommandLine.arguments[1])! n = end n = n / 2 * 2 diff --git a/matmul/matmul_d_lubeck.d b/matmul/matmul_d_lubeck.d new file mode 100644 index 00000000..4358c689 --- /dev/null +++ b/matmul/matmul_d_lubeck.d @@ -0,0 +1,53 @@ +#!/usr/bin/env dub +/+dub.sdl: +dependency "lubeck" version="~>1.1.7" +libs "lapack" "blas" ++/ + +import core.stdc.stdio, std.conv, std.array; +import mir.ndslice; +import lubeck: mtimes; + +alias Matrix = Slice!(double*, 2); + +Matrix buildMatrix(size_t n) +{ + auto len = n * n; + double tmp = 1.0 / len; + auto a = slice!double(n, n); + size_t i; + foreach (ref row; a) + { + sizediff_t u = i, v = i; + foreach (ref x; row) + { + x = tmp * (u * v); + u--; + v++; + } + i++; + } + return a; +} + +Matrix[2] generate2(size_t n) +{ + auto a = buildMatrix(n); + auto b = buildMatrix(n); + return [a, b]; +} + +Matrix mul(Matrix a, Matrix b) +{ + return a.mtimes(b); +} + +void main(in string[] args) +{ + size_t n = 100; + if (args.length >= 2) + n = to!size_t(args[1]) / 2 * 2; + auto ab = generate2(n); + auto x = mul(ab[0], ab[1]); + printf("%.6f\n", x[n / 2, n / 2]); +} diff --git a/matmul/matmul_d_mir.d b/matmul/matmul_d_mir.d deleted file mode 100644 index b022ced0..00000000 --- a/matmul/matmul_d_mir.d +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env dub -/+ dub.json: -{ - "name": "matmul_d_mir", - "dependencies": {"mir": "==0.18.0"}, - "dflags-ldc": ["-mcpu=native"], -} -+/ -//dub build --build=release-nobounds --single matmul_d_mir.d --compiler=ldmd2 - -// Writen by Attractive Chaos; distributed under the MIT license - -import core.stdc.stdio, std.conv, std.array; -import std.experimental.allocator.mallocator; -import mir.ndslice; -import mir.glas; - -alias Matrix = Slice!(2, double*); - -Matrix[2] generate2(size_t n) -{ - auto len = n * n; - double tmp = 1.0 / len; - auto ab = Mallocator.instance.makeUninitializedSlice!double([2, n, n]).slice; - auto a = ab[0]; - auto b = ab[1]; - size_t i; - foreach (row; assumeSameStructure!("a", "b")(a, b)) - { - sizediff_t u = i, v = i; - foreach (x; row) - { - x.a = x.b = tmp * (u * v); - u--; - v++; - } - i++; - } - return [a, b]; -} - -GlasContext ctx; -Matrix mul(Matrix a, Matrix b) -{ - auto c = Mallocator.instance.makeUninitializedSlice!double([a.length!0, b.length!1]).slice; - gemm(&ctx, 1.0, a, b, 0.0, c); - return c; -} - -void main(in string[] args) -{ - size_t n = 100; - if (args.length >= 2) - n = to!size_t(args[1]) / 2 * 2; - auto ab = generate2(n); - auto x = mul(ab[0], ab[1]); - printf("%.6f\n", x[n / 2, n / 2]); -} diff --git a/matmul/run-ruby.sh b/matmul/run-ruby.sh new file mode 100755 index 00000000..c661499b --- /dev/null +++ b/matmul/run-ruby.sh @@ -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 matmul.rb 1500 +done diff --git a/matmul/run.sh b/matmul/run.sh old mode 100644 new mode 100755 index 5aaf5954..26da0a83 --- a/matmul/run.sh +++ b/matmul/run.sh @@ -1,3 +1,5 @@ +#!/bin/sh + echo Crystal ../xtime.rb ./matmul_cr 1500 echo Go @@ -14,8 +16,8 @@ echo D Gdc ../xtime.rb ./matmul_d_gdc 1500 echo D Ldc ../xtime.rb ./matmul_d_ldc 1500 -echo D Mir GLAS -../xtime.rb ./matmul_d_mir 1500 +echo D lubeck +../xtime.rb ./matmul_d_lubeck 1500 echo Nim Gcc ../xtime.rb ./matmul_nim_gcc 1500 echo Nim Clang @@ -39,15 +41,13 @@ echo Julia echo Mono ../xtime.rb mono -O=all --gc=sgen matmul.exe 1500 echo C# .Net Core -../xtime.rb dotnet bin/Release/netcoreapp2.0/matmul.dll 1500 +../xtime.rb dotnet bin/Release/netcoreapp3.0/matmul.dll 1500 echo Python PyPy ../xtime.rb pypy matmul.py 1500 echo Python ../xtime.rb python matmul.py 1500 echo Python NumPy ../xtime.rb python matmul-numpy.py 1500 -echo Ruby Topaz -../xtime.rb topaz matmul.rb 1500 echo Ruby ../xtime.rb ruby matmul.rb 1500 echo Perl diff --git a/xtime.rb b/xtime.rb index c8cb6be4..fcd42d75 100755 --- a/xtime.rb +++ b/xtime.rb @@ -1,5 +1,14 @@ #!/usr/bin/env ruby -def mem(pid); `ps p #{pid} -o rss`.split.last.to_i; end +def mem(pid) + parent_rss = `ps p #{pid} -o rss` + children_rss = `ps --ppid #{pid} -o rss` + overall = parent_rss.split("\n").last.to_i + children_rss.split("\n").drop(1).each do |mem| + overall += mem.to_i + end + overall +end + t = Process.clock_gettime(Process::CLOCK_MONOTONIC) pid = Process.spawn(*ARGV.to_a) mm = 0