Skip to content

Instantly share code, notes, and snippets.

View LuceneQueryParser
using System.Globalization;
using Irony.Parsing;
namespace Grammar
{
[Language("LuceneGrammar", "1.0", "Lucene Grammar")]
public class LuceneGrammar : Irony.Parsing.Grammar
{
public LuceneGrammar()
: base(true) // true means case sensitive
@mattwarren
mattwarren / HistogramAllInOneClass.cs
Last active August 29, 2015 14:03
HistogramAllInOneClass
View HistogramAllInOneClass.cs
using CSharp.Atomic;
using HdrHistogram.NET.Iteration;
using HdrHistogram.NET.Utilities;
using LongBuffer = HdrHistogram.NET.Utilities.WrappedBuffer<long>;
namespace HdrHistogram.NET
{
public class HistogramAllInOneClass
{
internal static readonly AtomicLong constructionIdentityCount = new AtomicLong(0);
@mattwarren
mattwarren / LinqStreaming
Last active August 29, 2015 14:04
LINQ streaming
View LinqStreaming
static void Main(string[] args)
{
var items = new[] { 1, 2, 3, 4, 5 };
var test = items.Where(i =>
{
Console.WriteLine("Where: " + i);
return i > 3 ? true : false; // only keeps items > 3
})
.Select(i =>
{
View PerformanceRelated.txt
Everything I Ever Learned About JVM Performance Tuning @Twitter- by Attila Szegedi
http://www.infoq.com/presentations/JVM-Performance-Tuning-twitter (video & slides)
9 Fallacies of Java Performance - by Ben Evans
http://www.infoq.com/articles/9_Fallacies_Java_Performance (video & slides)
Visualizing Java GC - by Ben Evans
http://www.infoq.com/presentations/Visualizing-Java-GC (video & slides)
View gist:d8308d80bb7dbf5b8ac2
public static Dictionary<FieldInfo, int> FieldOffsetsInMemory(Type t)
{
try
{
var fields = t.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
var emit = Emit<Func<object, ulong[]>>.NewDynamicMethod("_GetOffsetsInMemory" + t.FullName);
var retLoc = emit.DeclareLocal<ulong[]>("ret");
emit.LoadConstant(fields.Length); // ulong
View ProfileNormal.asm
; 70: var watch = new Stopwatch();
000000b4 lea rcx,[5D3BB7F0h]
000000bb call 000000005F642050
000000c0 mov r12,rax
000000c3 mov rcx,r12
000000c6 call 000000005D254C50
000000cb movzx eax,byte ptr [r12+18h] ; The call to watch.Start() has been in-lined
000000d1 test eax,eax
000000d3 jne 00000000000000E5
000000d5 call 000000005D264320
View ProfileDirect.asm
; 91: var watch = new Stopwatch();
000000a6 lea rcx,[5D3EBA90h]
000000ad call 000000005F6722F0
000000b2 mov r12,rax
000000b5 mov rcx,r12
000000b8 call 000000005D284EF0
; 92: watch.Start();
000000bd mov rcx,r12
000000c0 call 000000005D284E60
; 93: for (int i = 0; i < iterations; i++)
View ProfileDirectWithStore.asm
; 127: var watch = new Stopwatch();
000000ac lea rcx,[5D3EB860h]
000000b3 call 000000005F6720C0
000000b8 mov rsi,rax
000000bb mov rcx,rsi
000000be call 000000005D294530
; 128: watch.Start();
000000c3 mov rcx,rsi
000000c6 call 000000005D284C30
; 129: for (int i = 0; i < iterations; i++)
View Math.Sqrt ProfileDirectWithStore 32-bit.asm
; 270: for (int i = 0; i < iterations; i++)
0000005f xor edx,edx
00000061 mov dword ptr [ebp-10h],edx
00000064 test ebx,ebx
00000066 jle 00000092
; 271: {
; 272: result = Math.Sqrt(123.456);
00000068 mov ecx,7277806Ch
0000006d call FFF22C08
00000072 mov esi,eax
View Math.Sqrt ProfileDirectWithStore 64-bit.asm
; 270: for (int i = 0; i < iterations; i++)
000000d3 mov r12d,dword ptr [rbp+68h]
000000d7 test r12d,r12d
000000da jle 0000000000000116
000000dc xor ebx,ebx
000000de xchg ax,ax
; 271: {
; 272: result = Math.Sqrt(123.456);
000000e0 sqrtsd xmm0,mmword ptr [000002A8h]
000000e8 movsd mmword ptr [rbp+20h],xmm0