Skip to content

Instantly share code, notes, and snippets.

View lahma's full-sized avatar

Marko Lahma lahma

View GitHub Profile
@lahma
lahma / SearchValues.cs
Created November 24, 2023 18:29
SearchValues shim for > 10 char basic ASCII strings
#if !NET8_0_OR_GREATER
using System.Runtime.CompilerServices;
namespace System.Buffers;
internal static class SearchValues
{
internal static SearchValues<char> Create(string input) => new(input.AsSpan());
internal static SearchValues<char> Create(ReadOnlySpan<char> input) => new(input);
@lahma
lahma / ExceptionBenchmark-report-github.md
Created April 26, 2023 07:14
Throw helper performance
BenchmarkDotNet=v0.13.5, OS=Windows 11 (10.0.22621.1555/22H2/2022Update/SunValley2)
12th Gen Intel Core i9-12900H, 1 CPU, 20 logical and 14 physical cores
.NET SDK=7.0.203
  [Host]     : .NET 6.0.16 (6.0.1623.17311), X64 RyuJIT AVX2
  DefaultJob : .NET 6.0.16 (6.0.1623.17311), X64 RyuJIT AVX2

@lahma
lahma / Jint.Benchmark.DromaeoBenchmark-report-github.md
Created November 10, 2022 06:41
3.0.0-beta-2043 with performance on different runtimes
BenchmarkDotNet=v0.13.2, OS=Windows 11 (10.0.22621.819)
AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores
.NET SDK=7.0.100
  [Host]             : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2
  .NET 6.0           : .NET 6.0.11 (6.0.1122.52304), X64 RyuJIT AVX2
  .NET 7.0           : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2
  .NET Framework 4.8 : .NET Framework 4.8.1 (4.8.9105.0), X64 RyuJIT VectorSize=256
 NativeAOT 7.0 : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2
@lahma
lahma / Jint.Benchmark.ArrayStressBenchmark-report-github.md
Created August 31, 2022 18:52
.NET JavaScript engine comparison 2022-08-31
BenchmarkDotNet=v0.13.2, OS=Windows 11 (10.0.22621.457)
AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores
.NET SDK=6.0.400
  [Host]     : .NET 6.0.8 (6.0.822.36306), X64 RyuJIT AVX2
  DefaultJob : .NET 6.0.8 (6.0.822.36306), X64 RyuJIT AVX2

@lahma
lahma / Program.cs
Last active January 25, 2022 19:30
Parametrized test case performance
using System.Collections;
using System.Diagnostics;
using System.Text;
using BenchmarkDotNet.Attributes;
using Jint.Tests.Test262;
using NUnit.Framework.Api;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Filters;
@lahma
lahma / StringBenchmark-report-github.md
Created December 23, 2021 07:12
String search experiments
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22000
AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores
.NET SDK=6.0.101
  [Host]     : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT
  Job-PVCLFY : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT
  Job-ZTLPVD : .NET Framework 4.8 (4.8.4420.0), X64 RyuJIT
[Fact]
public void ShouldParseNJsonSchema()
{
var source = @"
{%- if HasDescription %}
/** {{ Description }} */
{%- endif %}
{% if ExportTypes %}export {% endif %}{% if IsAbstract %}abstract {% endif %}class {{ ClassName }}{{ Inheritance }} {
{%- for property in Properties %}
{%- if property.HasDescription %}
@lahma
lahma / schema_class.liquid
Created March 26, 2021 19:06
NJsonSchema TypeScript class
{%- if HasDescription %}
/** {{ Description }} */
{%- endif %}
{% if ExportTypes %}export {% endif %}{% if IsAbstract %}abstract {% endif %}class {{ ClassName }}{{ Inheritance }} {
{%- for property in Properties %}
{%- if property.HasDescription %}
/** {{ property.Description }} */
{%- endif %}
{% if property.IsReadOnly %}readonly {% endif %}{{ property.PropertyName }}{% if property.IsOptional %}?{% elsif RequiresStrictPropertyInitialization and property.HasDefaultValue == false %}!{% endif %}: {{ property.Type }}{{ property.TypePostfix }};
{%- endfor %}
BenchmarkDotNet=v0.11.5, OS=Windows 10.0.18362
AMD Ryzen 7 2700X, 1 CPU, 16 logical and 8 physical cores
.NET Core SDK=3.0.100
  [Host]     : .NET Core 2.1.13 (CoreCLR 4.6.28008.01, CoreFX 4.6.28008.01), 64bit RyuJIT
  DefaultJob : .NET Core 2.1.13 (CoreCLR 4.6.28008.01, CoreFX 4.6.28008.01), 64bit RyuJIT

BenchmarkDotNet=v0.11.5, OS=Windows 10.0.18362
AMD Ryzen 7 2700X, 1 CPU, 16 logical and 8 physical cores
  [Host]     : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.8.3815.0
  DefaultJob : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.8.3815.0

| Type | Method | Engine | ReuseEngine | Mean | Error | StdDev | Median | Gen 0 | Gen 1 | Gen 2 | Allocated |