// 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; protected IMemoryOwner destination; 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()); } }