-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize DotvvmMetrics.ExponentialBuckets
The stupid prometheus-net library call this function for every single datapoint... I didn't want to cache the result arrays, as we'd have to undo that optimization when we add some configuration arguments to the TryGetRecommendedBuckets method.
- Loading branch information
Showing
2 changed files
with
55 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using DotVVM.Framework.Hosting; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace DotVVM.Framework.Tests.Runtime | ||
{ | ||
[TestClass] | ||
public class MetricsTests | ||
{ | ||
[TestMethod] | ||
public void IntLog() | ||
{ | ||
for (int i = 1; i < 100; i++) | ||
{ | ||
var log = DotvvmMetrics.IntegerLog2(i); | ||
var expectedLog = (int)Math.Log(i, 2); | ||
Assert.AreEqual(expectedLog, log); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void ExponentialBuckets() | ||
{ | ||
XAssert.Equal(new double[] { 1, 2, 4, 8, 16, 32, 64 }, DotvvmMetrics.ExponentialBuckets(1, 64)); | ||
XAssert.Equal(new double[] { 0.0078125, 0.015625, 0.03125, 0.0625, 0.125, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 64 }, DotvvmMetrics.TryGetRecommendedBuckets(DotvvmMetrics.RequestDuration)); | ||
|
||
} | ||
} | ||
} |