Skip to content

EgorBot for EgorBo in #112046 #281

@EgorBot

Description

@EgorBot

Processing dotnet/runtime#112046 (comment) command:

Command

-amd -arm -profiler --envvars JitDisasm:InversionMutation

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;

public class Benchmarks
{
    private const int Seed = 100;

    private static readonly int[] Chromosome = new int[59];
    private static readonly Random Random = new(Seed);

    public Benchmarks()
    {
        var genes = Enumerable.Range(1, 59).ToArray();
        Random.Shuffle(genes);
        genes.CopyTo(Chromosome.AsSpan());
    }

    [Benchmark]
    public int[] InversionMutation()
    {
        var idx1 = 0;
        var idx2 = 0;

        var chromosomeLength = Chromosome.Length;

        while (idx1 == idx2)
        {
            idx1 = Random.Next(chromosomeLength);
            idx2 = Random.Next(chromosomeLength);
        }

        if (idx1 > idx2)
        {
            (idx1, idx2) = (idx2, idx1);
        }

        Array.Reverse(Chromosome, idx1, idx2 - idx1 + 1);

        return Chromosome;
    }
}

(EgorBot will reply in this issue)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions