Skip to content

Commit

Permalink
Minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
WorkingRobot committed Nov 14, 2023
1 parent bdce750 commit 3895e1f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Craftimizer/ImGuiUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public ViolinData(IEnumerable<int> samples, float min, float max, int resolution
var samplesList = samples.AsParallel().Select(s => (double)s).ToArray();
_ = Task.Run(() => {
var s = Stopwatch.StartNew();
var data = ParallelEnumerable.Range(0, resolution)
var data = ParallelEnumerable.Range(0, resolution + 1)
.Select(n => Lerp(min, max, n / (float)resolution))
.Select(n => (n, (float)KernelDensity.EstimateGaussian(n, bandwidth, samplesList)))
.Select(n => new Point(n.n, n.Item2, -n.Item2));
Expand All @@ -268,10 +268,9 @@ public static void ViolinPlot(in ViolinData data, Vector2 size)
{
using var padding = ImRaii2.PushStyle(ImPlotStyleVar.PlotPadding, Vector2.Zero);
using var plotBg = ImRaii2.PushColor(ImPlotCol.PlotBg, Vector4.Zero);
using var frameBg = ImRaii2.PushColor(ImPlotCol.FrameBg, Vector4.Zero);
using var fill = ImRaii2.PushColor(ImPlotCol.Fill, Vector4.One.WithAlpha(.5f));

using var plot = ImRaii2.Plot("##violin", size, ImPlotFlags.CanvasOnly);
using var plot = ImRaii2.Plot("##violin", size, ImPlotFlags.CanvasOnly | ImPlotFlags.NoInputs | ImPlotFlags.NoChild | ImPlotFlags.NoFrame);
if (plot)
{
ImPlot.SetupAxes(null, null, ImPlotAxisFlags.NoDecorations, ImPlotAxisFlags.NoDecorations | ImPlotAxisFlags.AutoFit);
Expand All @@ -280,7 +279,8 @@ public static void ViolinPlot(in ViolinData data, Vector2 size)

if (data.Data is { } points && !points.IsEmpty)
{
unsafe {
unsafe
{
var label_id = stackalloc byte[] { (byte)'\0' };
fixed (ViolinData.Point* p = points)
{
Expand Down
2 changes: 1 addition & 1 deletion Craftimizer/Windows/MacroEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ private void DrawBars(IEnumerable<BarData> bars)
{
if (bar.Reliability is { } reliability)
{
if (reliability.GetViolinData(bar.Max, (int)(barSize / 2), 0.02) is { } violinData)
if (reliability.GetViolinData(bar.Max, (int)(barSize / 5), 0.02) is { } violinData)
{
ImGui.SetCursorPos(pos);
ImGuiUtils.ViolinPlot(violinData, new(barSize, ImGui.GetFrameHeight()));
Expand Down

1 comment on commit 3895e1f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 3895e1f Previous: 4bf7397 Ratio
Craftimizer.Benchmark.Bench.Solve(State: 5372D31C98FA4C357F54029912394B0F5ECBE94AEC9D12C1C2B7F453C62ACD2F, Config: B75845A5DEDC79F3C98FE35F28206855B0EF4E065555FAF2AA129AED115B7744) 1502498173.3333333 ns (± 4056224.207043975) 1480306700 ns (± 23679878.252854258) 1.01
Craftimizer.Benchmark.Bench.Solve(State: 5372D31C98FA4C357F54029912394B0F5ECBE94AEC9D12C1C2B7F453C62ACD2F, Config: B75845A5DEDC79F3C98FE35F28206855B0EF4E065555FAF2AA129AED115B7744) 1049513346.6666666 ns (± 2503156.845398759) 1480306700 ns (± 23679878.252854258) 0.71
Craftimizer.Benchmark.Bench.Solve(State: 99B0F1AD46A18B4D8262F9BA75ABE23507217C2F20FBF895A49282DDFEF50190, Config: B75845A5DEDC79F3C98FE35F28206855B0EF4E065555FAF2AA129AED115B7744) 1477587571.4285715 ns (± 5905441.633902462) 1450385066.6666667 ns (± 6712458.243197247) 1.02
Craftimizer.Benchmark.Bench.Solve(State: 99B0F1AD46A18B4D8262F9BA75ABE23507217C2F20FBF895A49282DDFEF50190, Config: B75845A5DEDC79F3C98FE35F28206855B0EF4E065555FAF2AA129AED115B7744) 1218395507.6923077 ns (± 4210438.969090503) 1450385066.6666667 ns (± 6712458.243197247) 0.84

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.