Skip to content

Instantly share code, notes, and snippets.

View lahma's full-sized avatar

Marko Lahma lahma

View GitHub Profile
using System;
using System.IO;
using System.Net.Http;
using Raven.Client.Documents.Conventions;
using Raven.Client.Documents.Operations;
@lahma
lahma / Benchmark.cs
Last active January 8, 2019 20:55
Esprima.Ast.List<T> vs System.Collections.Generic.List<T>
using BenchmarkDotNet.Attributes;
namespace Esprima.Benchmark
{
[MemoryDiagnoser]
public class ListBenchmark
{
private const int Size = 10_000;
private Ast.List<int> _astList;
private System.Collections.Generic.List<int> _bclList;
@lahma
lahma / Jint.md
Created December 26, 2018 19:56
JS Engine Performance 2018-12-26
BenchmarkDotNet=v0.11.3, OS=Windows 10.0.17763.195 (1809/October2018Update/Redstone5)
Intel Core i7-6820HQ CPU 2.70GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
  [Host]     : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.3260.0
  DefaultJob : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.3260.0

| Method | FileName | Mean | Error | StdDev | Gen 0/1k Op | Gen 1/1k Op | Gen 2/1k Op | Allocated Memory/Op |

@lahma
lahma / DistinctBenchmark.cs
Created December 21, 2018 07:04
JavaScript distinct, new Jint Set
using BenchmarkDotNet.Attributes;
namespace Jint.Benchmark
{
[MemoryDiagnoser]
public class DistinctBenchmark
{
private const string script = @"
var x = {'Items':[{'ItemId':'the-item--1'},{'ItemId':'the-item-1'},{'ItemId':'the-item-1'},{'ItemId':'the-item-3'},{'ItemId':'the-item-3'},{'ItemId':'the-item-5'},{'ItemId':'the-item-5'},{'ItemId':'the-item-7'},{'ItemId':'the-item-7'},{'ItemId':'the-item-9'},{'ItemId':'the-item-9'},{'ItemId':'the-item-11'},{'ItemId':'the-item-11'},{'ItemId':'the-item-13'},{'ItemId':'the-item-13'},{'ItemId':'the-item-15'},{'ItemId':'the-item-15'},{'ItemId':'the-item-17'},{'ItemId':'the-item-17'},{'ItemId':'the-item-19'},{'ItemId':'the-item-19'},{'ItemId':'the-item-21'},{'ItemId':'the-item-21'},{'ItemId':'the-item-23'},{'ItemId':'the-item-23'},{'ItemId':'the-item-25'},{'ItemId':'the-item-25'},{'ItemId':'the-item-27'},{'ItemId':'the-item-27'},{'ItemId':'the-item-29'},{'ItemId':'the-item-29'},{'ItemId':'the-item-31'},{'ItemId':'the-item-31'},{'ItemId':'the-item-33'},
internal class JintLiteralExpression : JintExpression
{
internal readonly JsValue _cachedValue;
public JintLiteralExpression(Engine engine, Literal expression) : base(engine, expression)
{
_cachedValue = ConvertToJsValue(expression);
}
internal static JsValue ConvertToJsValue(Literal literal)
public class C {
public bool LoopAnyNonNull(string[] array) {
foreach (var x in array) {
if (x != null)
return true;
}
return false;
}
}
public static bool operator !=(JsValue a, JsValue b)
{
if ((object)a == null)
{
if ((object)b == null)
{
return false;
}
return true;
public void IsValidStringForMyUseCase(JsString js) {
return js != null && js._value != null && && js._value.Length > 0;
}
public class C {
public bool LinqAnyNonNull(string[] array) {
return array.Where(x => x != null).Any();
}
}
// produces following IL
.class public auto ansi beforefieldinit C
extends [mscorlib]System.Object
BenchmarkDotNet=v0.11.1, OS=Windows 10.0.17763
Intel Core i7-6820HQ CPU 2.70GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
  [Host]     : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.3190.0
  DefaultJob : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.3190.0

| Method | Mean | Error | StdDev | Scaled | ScaledSD | Allocated |