<commit_before>﻿// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.Xunit.Performance;
using Microsoft.Xunit.Performance.Api;
using System;
using System.Reflection;
using Xunit;

[assembly: OptimizeForBenchmarks]

// Test code taken directly from GitHub issue #9692 (https://github.com/dotnet/coreclr/issues/9692)
// Laying the loop's early return path in-line can cost 30% on this micro-benchmark.

namespace Layout
{
    public unsafe class SearchLoops
    {
        public static int Main(string[] args)
        {
            // Make sure equal strings compare as such
            if (!LoopReturn("hello", "hello") || !LoopGoto("goodbye", "goodbye"))
            {
                return -1;
            }

            // Make sure not-equal strings compare as such
            if (LoopReturn("hello", "goodbye") || LoopGoto("goodbye", "hello"))
            {
                return -1;
            }

            // Success
            return 100;
        }

        public int length = 100;

        private string test1;
        private string test2;

        public SearchLoops()
        {
            test1 = new string('A', length);
            test2 = new string('A', length);
        }

        [Benchmark]
        public void LoopReturn()
        {
            Benchmark.Iterate(() => LoopReturn(test1, test2));
        }

        [Benchmark]
        public void LoopGoto()
        {
            Benchmark.Iterate(() => LoopGoto(test1, test2));<commit_msg>Add InnerIterationCount to layout benchmarks<commit_after>﻿// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.Xunit.Performance;
using Microsoft.Xunit.Performance.Api;
using System;
using System.Reflection;
using Xunit;

[assembly: OptimizeForBenchmarks]

// Test code taken directly from GitHub issue #9692 (https://github.com/dotnet/coreclr/issues/9692)
// Laying the loop's early return path in-line can cost 30% on this micro-benchmark.

namespace Layout
{
    public unsafe class SearchLoops
    {
        public static int Main(string[] args)
        {
            // Make sure equal strings compare as such
            if (!LoopReturn("hello", "hello") || !LoopGoto("goodbye", "goodbye"))
            {
                return -1;
            }

            // Make sure not-equal strings compare as such
            if (LoopReturn("hello", "goodbye") || LoopGoto("goodbye", "hello"))
            {
                return -1;
            }

            // Success
            return 100;
        }

        public int length = 100;

        private string test1;
        private string test2;

        public SearchLoops()
        {
            test1 = new string('A', length);
            test2 = new string('A', length);
        }

        [Benchmark(InnerIterationCount = 20000000)]
        public void LoopReturn()
        {
            Benchmark.Iterate(() => LoopReturn(test1, test2));
        }

        [Benchmark(InnerIterationCount = 20000000)]
        public void LoopGoto()
        {
            Benchmark.Iterate(() => LoopGoto(test1, test2));
{'fraction_non_alphanumeric': 0.10038610038610038, 'fraction_numerical': 0.020196020196020195, 'mean_word_length': 1.9884649511978705, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4507470', 'n_tokens_mistral': 960, 'n_tokens_neox': 883, 'n_words': 293}