public void Run() { var competition = new BenchmarkCompetition(); competition.AddTask("Single", () => single = new int[N * M], () => SingleRun(single)); competition.AddTask("Jagged", () => { jagged = new int[N][]; for (int i = 0; i < N; i++) { jagged[i] = new int[M]; } }, () => JaggedRun(jagged)); competition.AddTask("Rectangular", () => rectangular = new int[N, M], () => RectangularRun(rectangular)); competition.Run(); }
public void Run() { var competition = new BenchmarkCompetition(); competition.AddTask("Shift", () => Shift()); competition.AddTask("Multiply", () => Multiply()); competition.Run(); }
public void Run() { var competition = new BenchmarkCompetition(); competition.AddTask("i++", () => After()); competition.AddTask("++i", () => Before()); competition.Run(); }
public void Run() { array = new int[5]; var competition = new BenchmarkCompetition(); competition.AddTask("MakeRef", MakeRef); competition.AddTask("Boxing", Boxing); competition.Run(); }
public void Run() { nonStaticField = staticField = new int[N]; var competition = new BenchmarkCompetition(); competition.AddTask("Non-static/unroll", () => NonStaticUnrollRun()); competition.AddTask("Static/unroll", () => StaticUnrollRun()); competition.AddTask("Non-static", () => NonStaticRun()); competition.AddTask("Static", () => StaticRun()); competition.Run(); }
static void Main() { var dataManager = CreateDataManager(); dataManager.Initialize(); var listRunner = new ListRunner(dataManager); var linqRunner = new LinqRunner(dataManager); var strategyRunner = new StrategyRunner(dataManager); BenchmarkSettings.Instance.DetailedMode = true; var competition = new BenchmarkCompetition(); competition.AddTask("List", listRunner.Run); competition.AddTask("LINQ", linqRunner.Run); competition.AddTask("Strategy", strategyRunner.Run); competition.Run(); }
private static readonly string[] runOnly = new string[0]; //{ "ArrayAccessCompetition" }; #endregion Fields #region Methods public static void Main() { BenchmarkSettings.Instance.DefaultPrintBenchmarkBodyToConsole = false; BenchmarkSettings.Instance.DetailedMode = true; var competition = new BenchmarkCompetition(); Assembly.GetExecutingAssembly() .GetTypes() .Where(x => !x.IsAbstract && typeof (CompetitionBase).IsAssignableFrom(x)) .Where(x => !runOnly.Any() || runOnly.Contains(x.Name)) .Select(type => { try { return new { type, instance = Activator.CreateInstance(type) }; } catch (Exception e) { Console.WriteLine("Failed: cannot create instance of type {0}:\n{1}", type, e); return null; } }) .Where(x => x != null) .SelectMany(x => x.type .GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static) .Where(method => method.HasAttribute<BenchmarkAttribute>()) .Select(method => new { x.type, x.instance, method })) .ForEach(x => { object benchmarkAction = x.method.IsStatic ? x.method.Invoke(null, new object[0]) : x.method.Invoke(x.instance, new object[0]); competition.AddTask(x.type.Name + "/" + x.method.Name, (Action) benchmarkAction); }); competition.Run(); }
public void Run() { originalData = new int[N]; var random = new Random(RandSeed); for (int i = 0; i < N; i++) { originalData[i] = random.Next() % 50; } var competition = new BenchmarkCompetition(); competition.AddTask("Linq", Initalize, LinqSort); competition.AddTask("CompareTo", Initalize, CompareToSort); competition.AddTask("(a,b)=>b-a", Initalize, ComparerMinusSort); competition.AddTask("Reverse", Initalize, ReverseSort); competition.Run(); }