diff --git a/.gitignore b/.gitignore index 07ba847..c5f1f2e 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,7 @@ msbuild.err msbuild.wrn # Visual Studio 2015 -.vs/ \ No newline at end of file +.vs/ + +*.class +perf \ No newline at end of file diff --git a/perfs/README.md b/perfs/README.md new file mode 100644 index 0000000..0e9cb6e --- /dev/null +++ b/perfs/README.md @@ -0,0 +1,42 @@ +# Performance + +Platform: Intel(R) Core(TM) i5-4308U CPU @ 2.80GHz / 16GB 1600 MHz DDR3 + +```sh +$ clang --version +Apple clang version 11.0.0 (clang-1100.0.33.12) +Target: x86_64-apple-darwin19.0.0 +$ clang -O3 perf.c -o perf +$ time ./perf +0.66 real 0.64 user 0.00 sys +$ time for i in {1..30}; do ./perf; done +real 0m19.697s +user 0m19.356s +sys 0m0.086s +``` + +```sh +$ java --version +openjdk 11.0.4 2019-07-16 +OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.4+11) +OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.4+11, mixed mode) +$ javac Perf.java +$ time java Perf +2.83 real 2.74 user 0.04 sys +$ time for i in {1..30}; do java Perf; done +real 1m23.663s +user 1m21.008s +sys 0m1.173s +``` + +```sh +$dotnet --version +3.0.100 +$ dotnet publish -r osx-x64 -c release /p:PublishSingleFile=true +$ time bin/release/netcoreapp3.0/osx-x64/publish/perfs +1.08 real 1.04 user 0.03 sys +$ time for i in {1..30}; do bin/release/netcoreapp3.0/osx-x64/publish/perfs; done +real 0m38.211s +user 0m31.473s +sys 0m0.958s +``` \ No newline at end of file diff --git a/perfs/clang/perf.c b/perfs/clang/perf.c new file mode 100644 index 0000000..bdd1d1d --- /dev/null +++ b/perfs/clang/perf.c @@ -0,0 +1,15 @@ +#include +#include + +long Sum(long a, long b){ + return a + b + rand(); +} + +int main(void){ + long sum = 0; + for (long count = 0; count < pow(10,8); count++) + { + sum = Sum(sum, count); + } + return (int)sum; +} \ No newline at end of file diff --git a/perfs/cs/Program.cs b/perfs/cs/Program.cs new file mode 100644 index 0000000..eb3f6e3 --- /dev/null +++ b/perfs/cs/Program.cs @@ -0,0 +1,22 @@ +using System; + +namespace perfs +{ + class Program + { + private static readonly Random random = new Random(); + + static long Sum(long a, long b) + { + return a + b + random.Next(); + } + static void Main(string[] args) + { + long sum = 0; + for (long count = 0; count < Math.Pow(10, 8); count++) + { + sum = Sum(sum, count); + } + } + } +} diff --git a/perfs/cs/perfs.csproj b/perfs/cs/perfs.csproj new file mode 100644 index 0000000..958d2f1 --- /dev/null +++ b/perfs/cs/perfs.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.0 + + + diff --git a/perfs/java/Perf.java b/perfs/java/Perf.java new file mode 100644 index 0000000..16855a8 --- /dev/null +++ b/perfs/java/Perf.java @@ -0,0 +1,18 @@ +import java.lang.Math; +import java.util.Random; + +public class Perf { + private static Random random = new Random(); + + public static long Sum(long a, long b){ + return a + b + random.nextInt(); + } + + public static void main(String args[]) { + long sum = 0; + for(long count = 0; count < Math.pow(10, 8); count++) + { + sum = Sum(sum, count); + } + } +} \ No newline at end of file