// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. using System.Buffers; using System.Numerics; using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Benchmarks.Bulk; public abstract class ToVector4 where TPixel : unmanaged, IPixel { protected IMemoryOwner Source { get; set; } protected IMemoryOwner Destination { get; set; } protected Configuration Configuration => Configuration.Default; [Params(64, 256, 2048)] // 512, 1024 public int Count { get; set; } [GlobalSetup] public void Setup() { this.Source = this.Configuration.MemoryAllocator.Allocate(this.Count); this.Destination = this.Configuration.MemoryAllocator.Allocate(this.Count); } [GlobalCleanup] public void Cleanup() { this.Source.Dispose(); this.Destination.Dispose(); } // [Benchmark] public void Naive() { Span s = this.Source.GetSpan(); Span d = this.Destination.GetSpan(); for (int i = 0; i < this.Count; i++) { d[i] = s[i].ToVector4(); } } [Benchmark] public void PixelOperations_Specialized() => PixelOperations.Instance.ToVector4( this.Configuration, this.Source.GetSpan(), this.Destination.GetSpan()); }