Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Immutable;
- using BenchmarkDotNet.Attributes;
- using BenchmarkDotNet.Jobs;
- using BenchmarkDotNet.Running;
- namespace Benchmark
- {
- [SimpleJob(RuntimeMoniker.CoreRt50)]
- public class Md5VsSha256
- {
- [Params(10, 100, 1000)]
- public int N;
- private ImmutableArray<int> data;
- [GlobalSetup]
- public void Setup()
- {
- var random = new Random();
- var builder = ImmutableArray.CreateBuilder<int>(N);
- for (int i = 0; i < N; ++i)
- {
- builder.Add(random.Next());
- }
- data = builder.MoveToImmutable();
- }
- static int ViaRef(in ImmutableArray<int> array)
- {
- int sum = 0;
- foreach (var i in array)
- {
- sum += i;
- }
- return sum;
- }
- static int ViaValue(ImmutableArray<int> array)
- {
- int sum = 0;
- foreach (var i in array)
- {
- sum += i;
- }
- return sum;
- }
- [Benchmark]
- public int Ref()
- {
- return ViaRef(data);
- }
- [Benchmark]
- public int Value()
- {
- return ViaValue(data);
- }
- }
- public static class Program
- {
- public static void Main()
- {
- BenchmarkRunner.Run<Md5VsSha256>();
- }
- }
- }
Add Comment
Please, Sign In to add comment