using System; class Base {} class Derived: Base {} public class GuardClass { const int N = 100000; private static Base[] objs = new Base[N]; public static void Init(string[] argv) { for (int i=0; i < N; i++) { if (i % 2 == 0) objs[i] = new Base(); else objs[i] = new Derived(); } } [Benchmark] public static int TestGuardClass() { int count = 0; for(int j=0; j < 1000; j++) for(int i=0; i < N; i++) if (objs[i].GetType() == typeof(Derived)) count++; return count; } [Benchmark] public static int TestIsInstance() { int count = 0; for(int j=0; j < 1000; j++) for(int i=0; i < N; i++) if (objs[i] is Derived) count++; return count; } }