Skip to content

Commit feed2a9

Browse files
authored
write results to csv (#130)
* write to excel * add results * fix percentage output
1 parent f44c577 commit feed2a9

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

BitFaster.Caching.HitRateAnalysis/Wikibench/Analysis.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.IO;
35
using System.Linq;
46
using System.Text;
57
using System.Threading.Tasks;
68
using BitFaster.Caching.Lru;
9+
using CsvHelper;
710

811
namespace BitFaster.Caching.HitRateAnalysis.Wikibench
912
{
@@ -18,6 +21,12 @@ public Analysis(int cacheSize)
1821
this.classicLru = new ClassicLru<Uri, int>(1, cacheSize, EqualityComparer<Uri>.Default);
1922
}
2023

24+
public int CacheSize => this.concurrentLru.Capacity;
25+
26+
public double ConcurrentLruHitRate => this.concurrentLru.HitRatio * 100;
27+
28+
public double ClassicLruHitRate => this.classicLru.HitRatio * 100;
29+
2130
public void TestUri(Uri uri)
2231
{
2332
this.concurrentLru.GetOrAdd(uri, u => 1);
@@ -33,5 +42,14 @@ private static string FormatHits(double hitRate)
3342
{
3443
return string.Format("{0:N2}%", hitRate * 100.0);
3544
}
45+
46+
public static void WriteToFile(string path, IEnumerable<Analysis> results)
47+
{
48+
using (var writer = new StreamWriter(path))
49+
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
50+
{
51+
csv.WriteRecords(results);
52+
}
53+
}
3654
}
3755
}

BitFaster.Caching.HitRateAnalysis/Wikibench/Runner.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public static async Task Run()
5050
{
5151
a.Compare();
5252
}
53+
54+
Analysis.WriteToFile("results.wikibench.csv", analysis);
5355
}
5456
}
5557
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CacheSize,ConcurrentLruHitRate,ClassicLruHitRate
2+
25,30.748543935794594,12.339894258281078
3+
50,38.54143501776577,21.441939220308402
4+
75,42.52123346830987,27.84286871100062
5+
100,45.1025591654474,32.25609649363885
6+
125,47.21936919103159,35.30941454952625
7+
150,48.687634020955905,37.484624347754924
8+
175,49.932971822611414,39.10013286561485
9+
200,50.83386468801666,40.35904822418645

0 commit comments

Comments
 (0)