From 3f4e05c811fe272439609f765b460d8e2236713e Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 19 Dec 2021 21:57:57 +0100 Subject: [PATCH] Buffer2D_DangerousGetRowSpan benchmark --- .../General/Buffer2D_DangerousGetRowSpan.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/ImageSharp.Benchmarks/General/Buffer2D_DangerousGetRowSpan.cs diff --git a/tests/ImageSharp.Benchmarks/General/Buffer2D_DangerousGetRowSpan.cs b/tests/ImageSharp.Benchmarks/General/Buffer2D_DangerousGetRowSpan.cs new file mode 100644 index 000000000..84f035583 --- /dev/null +++ b/tests/ImageSharp.Benchmarks/General/Buffer2D_DangerousGetRowSpan.cs @@ -0,0 +1,42 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using BenchmarkDotNet.Attributes; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Benchmarks.General +{ + public class Buffer2D_DangerousGetRowSpan + { + [Params(true, false)] + public bool IsDiscontiguousBuffer { get; set; } + + private Buffer2D buffer; + + [GlobalSetup] + public void Setup() + { + MemoryAllocator allocator = Configuration.Default.MemoryAllocator; + this.buffer = this.IsDiscontiguousBuffer + ? allocator.Allocate2D(4000, 1000) + : allocator.Allocate2D(500, 1000); + } + + [GlobalCleanup] + public void Cleanup() => this.buffer.Dispose(); + + [Benchmark] + public int DangerousGetRowSpan() => + this.buffer.DangerousGetRowSpan(1).Length + + this.buffer.DangerousGetRowSpan(999).Length; + + // BenchmarkDotNet=v0.13.0, OS=Windows 10.0.19044 + // Intel Core i9-10900X CPU 3.70GHz, 1 CPU, 20 logical and 10 physical cores + // + // | Method | IsDiscontiguousBuffer | Mean | Error | StdDev | + // |-------------------- |---------------------- |---------:|---------:|---------:| + // | DangerousGetRowSpan | False | 74.96 ns | 1.505 ns | 1.478 ns | + // | DangerousGetRowSpan | True | 71.49 ns | 1.446 ns | 2.120 ns | + } +}