Skip to content

Commit

Permalink
Added performance benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
wizche committed Nov 29, 2019
1 parent 0346a07 commit 9d8a806
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ msbuild.err
msbuild.wrn

# Visual Studio 2015
.vs/
.vs/

*.class
perf
42 changes: 42 additions & 0 deletions perfs/README.md
Original file line number Diff line number Diff line change
@@ -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
```
15 changes: 15 additions & 0 deletions perfs/clang/perf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <math.h>
#include <stdlib.h>

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;
}
22 changes: 22 additions & 0 deletions perfs/cs/Program.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
8 changes: 8 additions & 0 deletions perfs/cs/perfs.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

</Project>
18 changes: 18 additions & 0 deletions perfs/java/Perf.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit 9d8a806

Please sign in to comment.