Skip to content

Instantly share code, notes, and snippets.

View ambrosiogabe's full-sized avatar

ambrosiogabe

View GitHub Profile
@ambrosiogabe
ambrosiogabe / Crafting.cs
Last active August 9, 2022 19:56
C# Crafting Recipe Comparison
// Results from Benchmark.NET
// | Method | Mean | Error | StdDev | Min | Max |
// |--------------- |---------:|--------:|--------:|---------:|---------:|
// | FindRecipe | 304.3 ns | 0.76 ns | 0.71 ns | 303.2 ns | 305.8 ns |
// | FastFindRecipe | 125.6 ns | 0.27 ns | 0.25 ns | 125.3 ns | 126.1 ns |
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Diagnostics.CodeAnalysis;
@ambrosiogabe
ambrosiogabe / How "slow" is brute force?.cpp
Last active January 30, 2023 15:28
A bunch of smart YouTube viewers said my algorithm is horribly inefficient since it was O(n) and I could have used a hash reducing it to O(1). Well, it turns out they were right, except somehow they forgot to account for the data set size which is a big impact on how slow the algorithm *actually* is. Whoopsy!
// System Specs
// ============
// These benchmarks were run on an Intel i7-9700k @ 3.6 GHz
//
// How it was run
// ===============
// The correct recipe is at the very end of the list of recipes. Which means this must run
// through the entire list, the worst case scenario. The rest of the recipes are randomized
// to offer some variation, but I don't set the slots where the correct recipe has the correct slots.
// to ensure we don't accidentally exit early.