This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from lewurm/isinst-bench
benchmarks: microbenchmark for `isinst` and `castclass`
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"Name": "isinst", | ||
"TestDirectory": "small", | ||
"CommandLine": ["isinst.exe", "25000000"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
Binary file not shown.