1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
6 using Microsoft.Xunit.Performance;
8 using System.Runtime.CompilerServices;
11 [assembly: OptimizeForBenchmarks]
13 namespace Benchstone.BenchI
15 public static class BenchE
18 public const int Iterations = 1;
20 public const int Iterations = 5000000;
23 private static int s_position;
25 private static int Strsch(char[] s, char[] k, int ns, int nk)
28 int start, ksave, cont;
34 cont = ns - nk + start;
35 kend = ksave + nk - 1;
41 // s is accessed upto cont i.e. ns - nk + 0
54 // j <= kend, so k is accessed upto 0 + nk - 1
63 r = ssave - start + 1;
68 private static void BenchInner(char[] s, char[] k)
74 s_position = Strsch(s, k, ns, nk);
77 [MethodImpl(MethodImplOptions.NoInlining)]
78 private static bool Bench()
81 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'H', 'E', 'R', 'E', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
82 'H', 'E', 'R', 'E', ' ', 'I', 'S', ' ', 'A', ' ', 'M', 'A', 'T', 'C', 'H', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'
85 char[] k = { 'H', 'E', 'R', 'E', ' ', 'I', 'S', ' ', 'A', ' ', 'M', 'A', 'T', 'C', 'H', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' };
87 for (int i = 0; i < Iterations; i++)
92 return (s_position == 91);
96 public static void Test()
98 foreach (var iteration in Benchmark.Iterations)
100 using (iteration.StartMeasurement())
107 private static bool TestBase()
109 bool result = Bench();
113 public static int Main()
115 bool result = TestBase();
116 return (result ? 100 : -1);