<commit_before>﻿using System;
using System.Collections;
using System.Linq;
using BenchmarkDotNet;
using NClone.MemberAccess;

namespace NClone.Benchmarks.Competitions
{
    public class ArrayAccessCompetition
    {
        private const int arraySize = 120000;

        private Array sourceArray;
        private Func<Array, int, object> getByAccessor;
        private Action<Array, int, object> setByAccessor;
        private object[] sourceObjArray;

        [Setup]
        public void SetUp()
        {
            var source = new int[arraySize];
            var random = new Random();
            for (var i = 0; i < arraySize; i++)
                source[i] = random.Next();

            sourceArray = source;
            sourceObjArray = source.Cast<object>().ToArray();

            var accessor = ArrayAccessorBuilder.BuildForArrayOf(typeof (int));
            getByAccessor = accessor.GetElement;
            setByAccessor = accessor.SetElement;
        }

        [Benchmark, OperationsPerInvoke(arraySize)]
        public void ViaMethods()
        {
            var destination = (Array) new int[arraySize];

            for (var i = 0; i < arraySize; ++i)
            {
                var data = sourceArray.GetValue(i);
                destination.SetValue(data, i);
            }

            Consume(destination);
        }

        [Benchmark, OperationsPerInvoke(arraySize)]
        public void ViaEmit()
        {
            var destination = (Array) new int[arraySize];

            for (var i = 0; i < arraySize; ++i)
            {
                var data = getByAccessor(sourceArray, i);
                setByAccessor(destination, i, data);
            }

            Consume(destination);
        }

        [Benchmark, OperationsPerInvoke(arraySize)]
        public void ViaCast()
        {
            var destination = new object[arraySize];

            for (var i = 0; i < arraySize; ++i)
            {
                var data = sourceObjArray[i];
                destination[i] = data;
            }

            Consume(destination);
        }

        [Benchmark, OperationsPerInvoke(arraySize)]
        public void ViaEnumerable()
        {<commit_msg>Remove useless benchmark<commit_after>﻿using System;
using System.Collections;
using System.Linq;
using BenchmarkDotNet;
using NClone.MemberAccess;

namespace NClone.Benchmarks.Competitions
{
    public class ArrayAccessCompetition
    {
        private const int arraySize = 120000;

        private Array sourceArray;
        private Func<Array, int, object> getByAccessor;
        private Action<Array, int, object> setByAccessor;

        [Setup]
        public void SetUp()
        {
            var source = new int[arraySize];
            var random = new Random();
            for (var i = 0; i < arraySize; i++)
                source[i] = random.Next();

            sourceArray = source;

            var accessor = ArrayAccessorBuilder.BuildForArrayOf(typeof (int));
            getByAccessor = accessor.GetElement;
            setByAccessor = accessor.SetElement;
        }

        [Benchmark, OperationsPerInvoke(arraySize)]
        public void ViaMethods()
        {
            var destination = (Array) new int[arraySize];

            for (var i = 0; i < arraySize; ++i)
            {
                var data = sourceArray.GetValue(i);
                destination.SetValue(data, i);
            }

            Consume(destination);
        }

        [Benchmark, OperationsPerInvoke(arraySize)]
        public void ViaEmit()
        {
            var destination = (Array) new int[arraySize];

            for (var i = 0; i < arraySize; ++i)
            {
                var data = getByAccessor(sourceArray, i);
                setByAccessor(destination, i, data);
            }

            Consume(destination);
        }

        [Benchmark, OperationsPerInvoke(arraySize)]
        public void ViaEnumerable()
        {
{'fraction_non_alphanumeric': 0.09178743961352658, 'fraction_numerical': 0.004830917874396135, 'mean_word_length': 1.776287932251235, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '530251', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1011, 'n_words': 263}