From 9f51bec24e2d780a4a57de0d937df4e8706847b2 Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Wed, 13 Apr 2016 17:03:31 -0700 Subject: [PATCH] benchmarks: microbenchmark for isinst and castclass --- benchmarks/isinst.benchmark | 5 ++++ tests/small/isinst.cs | 51 ++++++++++++++++++++++++++++++++++++ tests/small/isinst.exe | Bin 0 -> 3584 bytes 3 files changed, 56 insertions(+) create mode 100644 benchmarks/isinst.benchmark create mode 100644 tests/small/isinst.cs create mode 100755 tests/small/isinst.exe diff --git a/benchmarks/isinst.benchmark b/benchmarks/isinst.benchmark new file mode 100644 index 00000000..6bed184c --- /dev/null +++ b/benchmarks/isinst.benchmark @@ -0,0 +1,5 @@ +{ + "Name": "isinst", + "TestDirectory": "small", + "CommandLine": ["isinst.exe", "25000000"] +} diff --git a/tests/small/isinst.cs b/tests/small/isinst.cs new file mode 100644 index 00000000..d64c46a7 --- /dev/null +++ b/tests/small/isinst.cs @@ -0,0 +1,51 @@ +using System; + +public class MyTypes { + public class A { + public virtual long foo () { + return 1; + } + } + + public class B : A { + public override long foo () { + return 2; + } + } + + public class C : A { + public override long foo () { + return 3; + } + } + + static bool bench (long iterations, object[] objs) { + long checksum = 0; + for (long i = 0; i < iterations; ++i) { + foreach (object o in objs) { + if (o is A) { + checksum += ((A) o).foo (); + } + if (o is B) { + checksum += ((B) o).foo (); + } + if (o is C) { + checksum += ((C) o).foo (); + } + } + } + return checksum == (4 * iterations); + } + + public static void Main (string []args) { + long n = 25000000L; + object[] objs = new object[4]; + objs [0] = new object (); + objs [1] = new A (); + objs [2] = new B (); + objs [3] = new C (); + if (args.Length > 0) + n = Int64.Parse (args[0]); + System.Environment.Exit (bench (n, objs) ? 0 : 1); + } +} diff --git a/tests/small/isinst.exe b/tests/small/isinst.exe new file mode 100755 index 0000000000000000000000000000000000000000..c668ee0c8f4909bd46d8695e24c69abd0955d28b GIT binary patch literal 3584 zcmeHJO>7%Q6#jPO*v_Uk2`x@i^=G4`C<>J^YJgTMt(zv4K+{BZ5<&&EwzEyv*t^#5 zx^)mgxqu3&6>vaMaX`5vAwZ%6A#p$mB+7{!mkM#{jb6BLX!zc&o!C*;a)ypQGwKAZAO|S-K-ykaMRI_SNefNJPwUIr+W2UmfTU2h9tk`7t1Bki z2ux<_Vh6sdvyGw`dw4mHs&P_{0p3>_LCYHXbitt9u4J9s{dFzE*j?C8Z3}%-rIC!% z;+Qrm;?3R%)w+45y@wZZAN89``v42vvkkNT8^{P=P}&cgjfa>+uEl4EK7_t$KUH5_7Hgh@A!Gm}2v9s~W#lEMHUW)b%yvO;J}D^ruYHrh#iuEaLRmF(Nu zRXa54E>ug_VN5R1ELSX_H66t73_V7(NqH&5}ggOqI^1PcMA&&R;)G zel$1x+wUL$@`Tv62s9(XL5uUKbz|4gc&yzpc5>#`&~_!-V`3!I*e$naMo&KLIQj+n!+mU7)Om!bMP3)=6lj&OkQ!wPYf`qp1c`) zbF}*O=MWI*Qj_*NK8xJomKr$)MA@`2-X_xb3X?{fZ-R3iN08?T>?9+N&!~$sKNeR9 z+y(0D4L12IYX41@|$R$NfO