Skip to content

Commit

Permalink
Perf demo
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalBrylka committed Sep 23, 2024
1 parent b7772ce commit c0c0395
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 50 deletions.
44 changes: 0 additions & 44 deletions Benchmarks/BestPractices/CodeGen.cs

This file was deleted.

57 changes: 55 additions & 2 deletions Benchmarks/BestPractices/Demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,63 @@ BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config);
1. [BenchmarkInput.cs](https://github.com/nemesissoft/Nemesis.TextParsers/blob/ef14ecc52ac0275324b70e8e89a32192d6d734a7/Benchmarks/Helpers/BenchmarkInput.cs#L5)

# Samples
-
-
- [StringConcat](https://github.com/nemesissoft/Nemesis.TextParsers/blob/b7772ce4fe66381d301ad46213f67c077d35ae89/Benchmarks/StringConcatBench.cs#L53)
- [Generator](https://github.com/nemesissoft/Nemesis.TextParsers/blob/b7772ce4fe66381d301ad46213f67c077d35ae89/Benchmarks/BestPractices/GeneratorBench.cs#L16)
- [Nullable](https://github.com/nemesissoft/Nemesis.TextParsers/blob/b7772ce4fe66381d301ad46213f67c077d35ae89/Benchmarks/BestPractices/Nullable.cs#L12)
- [Boxing](https://github.com/nemesissoft/Nemesis.TextParsers/blob/b7772ce4fe66381d301ad46213f67c077d35ae89/Benchmarks/BestPractices/Boxing.cs#L12)
- [BoxingUnsafe](https://github.com/nemesissoft/Nemesis.TextParsers/blob/b7772ce4fe66381d301ad46213f67c077d35ae89/Benchmarks/BestPractices/BoxingUnsafe.cs#L12)
- [BoundsCheck](https://github.com/nemesissoft/Nemesis.TextParsers/blob/b7772ce4fe66381d301ad46213f67c077d35ae89/Benchmarks/BestPractices/BoundsCheck.cs#L20)
- [EnumParser](https://github.com/nemesissoft/Nemesis.TextParsers/blob/b7772ce4fe66381d301ad46213f67c077d35ae89/Benchmarks/EnumBenchmarks/EnumParserBench_CodeGen.cs#L30)
- [Linq](https://github.com/nemesissoft/Nemesis.TextParsers/blob/main/Benchmarks/LinqBench/Linq_WhereAndFirst_Vs_First.cs)
- [MultiKeyDictionary](https://github.com/nemesissoft/Nemesis.TextParsers/blob/b7772ce4fe66381d301ad46213f67c077d35ae89/Benchmarks/Collections/MultiKeyDictionaryBench.cs#L15)
- [Kafka deser](https://michalbrylka.github.io/posts/kafka-protobuf-deserializer/)

# CodeGen
[Compiler explorer](https://godbolt.org/)
```csharp
internal class CodeGen
{
static bool IsEven(int i) => (i % 2) == 0;
}
```

```assembly
; mono:
; Program:IsEven(System.Int32):System.Boolean:
sub rsp, 8
mov [rsp], r15
mov r15, rdi
mov rcx, r15
shr ecx, 1Fh
mov rax, r15
add eax, ecx
and rax, 1
sub eax, ecx
test eax, eax
sete al
movzx rax, al
mov r15, [rsp]
add rsp, 8
ret
; 6.0
; Program:IsEven(int):bool:
test dil, 1
sete al
movzx rax, al
ret
; 8.0
; Program:IsEven(int):bool (FullOpts):
G_M20272_IG01: ;; offset=0x0000
G_M20272_IG02: ;; offset=0x0000
mov eax, edi
not eax
and eax, 1
G_M20272_IG03: ;; offset=0x0007
ret
```


# Best practices
1. Lower error == better predictability
Expand Down
1 change: 0 additions & 1 deletion Benchmarks/BestPractices/EnumParserBench_CodeGen.cs

This file was deleted.

1 change: 0 additions & 1 deletion Benchmarks/BestPractices/LinqAllBench.cs

This file was deleted.

1 change: 0 additions & 1 deletion Benchmarks/BestPractices/MultiKeyDictionaryBench.cs

This file was deleted.

1 change: 0 additions & 1 deletion Benchmarks/BestPractices/StringConcatBench.cs

This file was deleted.

0 comments on commit c0c0395

Please sign in to comment.