ScottPlot / ScottPlot/ScottPlot
Histogramm: Optimize runtime by using better Add function for Histogramm
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 6.8k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
Suggestion:
The runtime of the add function is very slow if it is nessesary to set 100000 Bins or more.
To optimize the runtime of the Add function in Histogramm.Add(double value) i suggest this code.
I test the code with 100000 items in the Edges array and the values are the same as before.
/// <summary>
/// A histogram that accumulates the number of values observed in a continuous range of user defined bins
/// </summary>
public class Histogram
{
.....
public void Add(double value)
{
if (value < Edges[0])
{
if (IncludeOutliers)
Counts[0]++;
return;
}
int lastIndex = Edges.Length - 1;
if (value > Edges[lastIndex])
{
if (IncludeOutliers)
Counts[^1]++;
return;
}
int index = Array.BinarySearch(Edges, value);
if (index < 0)
index = ~index - 1;
// Ensure the last edge is included in the last bin
if (index == lastIndex)
Counts[Counts.Length - 1]++;
else
Counts[index]++;
}
...
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at Histogram.Add(double value), the method identified in the issue, and compare its current bin lookup with the proposed Array.BinarySearch approach. Validate that adding values with around 100000 entries in Edges produces the same Counts, including outliers and the final edge, while improving runtime.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- data-visualization, performance
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100