From 6ed650586b9bdec211252be0465beab8e474e406 Mon Sep 17 00:00:00 2001 From: Alex Peck Date: Wed, 15 May 2024 22:09:14 -0700 Subject: [PATCH 1/3] info --- .../Exporter.cs | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/BitFaster.Caching.ThroughputAnalysis/Exporter.cs b/BitFaster.Caching.ThroughputAnalysis/Exporter.cs index cdf92aca..24351f0f 100644 --- a/BitFaster.Caching.ThroughputAnalysis/Exporter.cs +++ b/BitFaster.Caching.ThroughputAnalysis/Exporter.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using CsvHelper; using Microsoft.FSharp.Core; using Plotly.NET; @@ -107,16 +108,36 @@ public void ExportPlot(Mode mode, int cacheSize) public string MapTitle(Mode mode, int cacheSize) { + string arch = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString(); + string fwk = RuntimeInformation.FrameworkDescription.ToString(); + + string os = "Win"; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + os = "Mac"; + } + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + os = "Linux"; + } + + if (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) + { + os = "BSD"; + } + switch (mode) { case Mode.Read: - return $"Read throughput (100% cache hit)"; + return $"Read throughput (100% cache hit) ({os}/{arch}/{fwk})"; case Mode.ReadWrite: - return $"Read + Write throughput"; + return $"Read + Write throughput ({os}/{arch}/{fwk})"; case Mode.Update: - return $"Update throughput"; + return $"Update throughput ({os}/{arch}/{fwk})"; case Mode.Evict: - return $"Eviction throughput (100% cache miss)"; + return $"Eviction throughput (100% cache miss) ({os}/{arch}/{fwk})"; default: return $"{mode} {cacheSize}"; } From ae7f6a91f307805aacafefb2d4666438ae16e895 Mon Sep 17 00:00:00 2001 From: Alex Peck Date: Fri, 17 May 2024 09:52:35 -0700 Subject: [PATCH 2/3] endl --- .../Exporter.cs | 372 +++++++++--------- 1 file changed, 186 insertions(+), 186 deletions(-) diff --git a/BitFaster.Caching.ThroughputAnalysis/Exporter.cs b/BitFaster.Caching.ThroughputAnalysis/Exporter.cs index 24351f0f..280acccc 100644 --- a/BitFaster.Caching.ThroughputAnalysis/Exporter.cs +++ b/BitFaster.Caching.ThroughputAnalysis/Exporter.cs @@ -1,196 +1,196 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using CsvHelper; -using Microsoft.FSharp.Core; -using Plotly.NET; -using Plotly.NET.ImageExport; -using Plotly.NET.LayoutObjects; - -namespace BitFaster.Caching.ThroughputAnalysis -{ - public class Exporter - { - DataTable resultTable = new DataTable(); - - public Exporter(int minThreads, int maxThreads) - { - // output: - // ThreadCount 1 2 3 4 5 - // Classic 5 6 7 7 8 - // Concurrent 5 6 7 7 8 - - resultTable.Clear(); - resultTable.Columns.Add("ThreadCount"); - foreach (var tc in Enumerable.Range(minThreads, maxThreads - (minThreads-1)).ToArray()) - { - resultTable.Columns.Add(tc.ToString()); - } - } - - public void Initialize(IEnumerable caches) - { - foreach (var c in caches) - { - c.DataRow = resultTable.NewRow(); - c.DataRow["ThreadCount"] = c.Name; - } - } - - public void CaptureRows(IEnumerable caches) - { - foreach (var c in caches) - { - resultTable.Rows.Add(c.DataRow); - } - } - - public void ExportCsv(Mode mode, int cacheSize) - { - using (var textWriter = File.CreateText($"Results_{mode}_{cacheSize}.csv")) - using (var csv = new CsvWriter(textWriter, CultureInfo.InvariantCulture)) - { - foreach (DataColumn column in resultTable.Columns) - { - csv.WriteField(column.ColumnName); - } - csv.NextRecord(); - - foreach (DataRow row in resultTable.Rows) - { - for (var i = 0; i < resultTable.Columns.Count; i++) - { - csv.WriteField(row[i]); - } - csv.NextRecord(); - } - } - } - - public void ExportPlot(Mode mode, int cacheSize) - { - var columns = new List(); - - for(int i = 1; i < resultTable.Columns.Count; i++) - { - columns.Add(int.Parse(resultTable.Columns[i].ColumnName)); - } - - List charts = new List(); - - foreach (DataRow row in resultTable.Rows) - { - var rowData = new List(); - string name = row[0].ToString(); - for (var i = 1; i < resultTable.Columns.Count; i++) - { - // convert back to millions - rowData.Add(double.Parse(row[i].ToString()) * 1_000_000); - } - - // var chart = Chart.Line(columns, rowData, Name: name, MarkerColor: MapColor(name)); - var chart = Chart2D.Chart.Line(columns, rowData, Name: name, MarkerColor: MapColor(name)); - charts.Add(chart); - - var combined = Chart.Combine(charts); - - combined - .WithLayout(MapTitle(mode, cacheSize)) - .WithoutVerticalGridlines() - .WithAxisTitles("Number of threads", "Ops/sec") - .SaveSVG($"Results_{mode}_{cacheSize}", Width: 1000, Height: 600); - } - } - - public string MapTitle(Mode mode, int cacheSize) - { - string arch = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString(); - string fwk = RuntimeInformation.FrameworkDescription.ToString(); - - string os = "Win"; - +using System; +using System.Collections.Generic; +using System.Data; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using CsvHelper; +using Microsoft.FSharp.Core; +using Plotly.NET; +using Plotly.NET.ImageExport; +using Plotly.NET.LayoutObjects; + +namespace BitFaster.Caching.ThroughputAnalysis +{ + public class Exporter + { + DataTable resultTable = new DataTable(); + + public Exporter(int minThreads, int maxThreads) + { + // output: + // ThreadCount 1 2 3 4 5 + // Classic 5 6 7 7 8 + // Concurrent 5 6 7 7 8 + + resultTable.Clear(); + resultTable.Columns.Add("ThreadCount"); + foreach (var tc in Enumerable.Range(minThreads, maxThreads - (minThreads-1)).ToArray()) + { + resultTable.Columns.Add(tc.ToString()); + } + } + + public void Initialize(IEnumerable caches) + { + foreach (var c in caches) + { + c.DataRow = resultTable.NewRow(); + c.DataRow["ThreadCount"] = c.Name; + } + } + + public void CaptureRows(IEnumerable caches) + { + foreach (var c in caches) + { + resultTable.Rows.Add(c.DataRow); + } + } + + public void ExportCsv(Mode mode, int cacheSize) + { + using (var textWriter = File.CreateText($"Results_{mode}_{cacheSize}.csv")) + using (var csv = new CsvWriter(textWriter, CultureInfo.InvariantCulture)) + { + foreach (DataColumn column in resultTable.Columns) + { + csv.WriteField(column.ColumnName); + } + csv.NextRecord(); + + foreach (DataRow row in resultTable.Rows) + { + for (var i = 0; i < resultTable.Columns.Count; i++) + { + csv.WriteField(row[i]); + } + csv.NextRecord(); + } + } + } + + public void ExportPlot(Mode mode, int cacheSize) + { + var columns = new List(); + + for(int i = 1; i < resultTable.Columns.Count; i++) + { + columns.Add(int.Parse(resultTable.Columns[i].ColumnName)); + } + + List charts = new List(); + + foreach (DataRow row in resultTable.Rows) + { + var rowData = new List(); + string name = row[0].ToString(); + for (var i = 1; i < resultTable.Columns.Count; i++) + { + // convert back to millions + rowData.Add(double.Parse(row[i].ToString()) * 1_000_000); + } + + // var chart = Chart.Line(columns, rowData, Name: name, MarkerColor: MapColor(name)); + var chart = Chart2D.Chart.Line(columns, rowData, Name: name, MarkerColor: MapColor(name)); + charts.Add(chart); + + var combined = Chart.Combine(charts); + + combined + .WithLayout(MapTitle(mode, cacheSize)) + .WithoutVerticalGridlines() + .WithAxisTitles("Number of threads", "Ops/sec") + .SaveSVG($"Results_{mode}_{cacheSize}", Width: 1000, Height: 600); + } + } + + public string MapTitle(Mode mode, int cacheSize) + { + string arch = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString(); + string fwk = RuntimeInformation.FrameworkDescription.ToString(); + + string os = "Win"; + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - os = "Mac"; + os = "Mac"; } if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - os = "Linux"; + os = "Linux"; } if (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) { - os = "BSD"; - } - - switch (mode) - { - case Mode.Read: - return $"Read throughput (100% cache hit) ({os}/{arch}/{fwk})"; - case Mode.ReadWrite: - return $"Read + Write throughput ({os}/{arch}/{fwk})"; - case Mode.Update: - return $"Update throughput ({os}/{arch}/{fwk})"; - case Mode.Evict: - return $"Eviction throughput (100% cache miss) ({os}/{arch}/{fwk})"; - default: - return $"{mode} {cacheSize}"; - } - } - - public Color MapColor(string name) - { - switch (name) - { - case "ClassicLru": - return Plotly.NET.Color.fromKeyword(Plotly.NET.ColorKeyword.Limegreen); - case "MemoryCache": - return Plotly.NET.Color.fromKeyword(Plotly.NET.ColorKeyword.FireBrick); - case "FastConcurrentLru": - return Plotly.NET.Color.fromKeyword(Plotly.NET.ColorKeyword.Silver); - case "ConcurrentLru": - return Plotly.NET.Color.fromKeyword(Plotly.NET.ColorKeyword.RoyalBlue); - case "ConcurrentLfu": - return Plotly.NET.Color.fromRGB(255, 192, 0); - default: - return Plotly.NET.Color.fromKeyword(Plotly.NET.ColorKeyword.FireBrick); - } - } - } - - public static class PlotExt - { - public static GenericChart.GenericChart WithAxisTitles(this GenericChart.GenericChart chart, string xTitle, string yTitle) - { - var font = new FSharpOption(Font.init(Size: new FSharpOption(16))); - FSharpOption xt = new FSharpOption(xTitle); - FSharpOption yt = new FSharpOption(yTitle); - return chart.WithXAxisStyle(Title.init(xt, Font: font)).WithYAxisStyle(Title.init(yt, Font: font)); - } - - public static GenericChart.GenericChart WithoutVerticalGridlines(this GenericChart.GenericChart chart) - { - var gridColor = new FSharpOption(Color.fromKeyword(ColorKeyword.Gainsboro)); - var yaxis = LinearAxis.init( - GridColor: gridColor, - ZeroLineColor: gridColor); - - var axis = LinearAxis.init(ShowGrid: new FSharpOption(false)); - return chart.WithXAxis(axis).WithYAxis(yaxis); - } - - public static GenericChart.GenericChart WithLayout(this GenericChart.GenericChart chart, string title) - { - var font = new FSharpOption(Font.init(Size: new FSharpOption(24))); - FSharpOption t = Title.init(Text: title, X: 0.5, Font: font); - FSharpOption<Color> plotBGColor = new FSharpOption<Color>(Color.fromKeyword(ColorKeyword.WhiteSmoke)); - Layout layout = Layout.init<IConvertible>(PaperBGColor: plotBGColor, PlotBGColor: plotBGColor, Title: t); - return chart.WithLayout(layout); - } - } -} + os = "BSD"; + } + + switch (mode) + { + case Mode.Read: + return $"Read throughput (100% cache hit) ({os}/{arch}/{fwk})"; + case Mode.ReadWrite: + return $"Read + Write throughput ({os}/{arch}/{fwk})"; + case Mode.Update: + return $"Update throughput ({os}/{arch}/{fwk})"; + case Mode.Evict: + return $"Eviction throughput (100% cache miss) ({os}/{arch}/{fwk})"; + default: + return $"{mode} {cacheSize}"; + } + } + + public Color MapColor(string name) + { + switch (name) + { + case "ClassicLru": + return Plotly.NET.Color.fromKeyword(Plotly.NET.ColorKeyword.Limegreen); + case "MemoryCache": + return Plotly.NET.Color.fromKeyword(Plotly.NET.ColorKeyword.FireBrick); + case "FastConcurrentLru": + return Plotly.NET.Color.fromKeyword(Plotly.NET.ColorKeyword.Silver); + case "ConcurrentLru": + return Plotly.NET.Color.fromKeyword(Plotly.NET.ColorKeyword.RoyalBlue); + case "ConcurrentLfu": + return Plotly.NET.Color.fromRGB(255, 192, 0); + default: + return Plotly.NET.Color.fromKeyword(Plotly.NET.ColorKeyword.FireBrick); + } + } + } + + public static class PlotExt + { + public static GenericChart.GenericChart WithAxisTitles(this GenericChart.GenericChart chart, string xTitle, string yTitle) + { + var font = new FSharpOption<Font>(Font.init(Size: new FSharpOption<double>(16))); + FSharpOption<string> xt = new FSharpOption<string>(xTitle); + FSharpOption<string> yt = new FSharpOption<string>(yTitle); + return chart.WithXAxisStyle(Title.init(xt, Font: font)).WithYAxisStyle(Title.init(yt, Font: font)); + } + + public static GenericChart.GenericChart WithoutVerticalGridlines(this GenericChart.GenericChart chart) + { + var gridColor = new FSharpOption<Color>(Color.fromKeyword(ColorKeyword.Gainsboro)); + var yaxis = LinearAxis.init<IConvertible, IConvertible, IConvertible, IConvertible, IConvertible, IConvertible>( + GridColor: gridColor, + ZeroLineColor: gridColor); + + var axis = LinearAxis.init<IConvertible, IConvertible, IConvertible, IConvertible, IConvertible, IConvertible>(ShowGrid: new FSharpOption<bool>(false)); + return chart.WithXAxis(axis).WithYAxis(yaxis); + } + + public static GenericChart.GenericChart WithLayout(this GenericChart.GenericChart chart, string title) + { + var font = new FSharpOption<Font>(Font.init(Size: new FSharpOption<double>(24))); + FSharpOption<Title> t = Title.init(Text: title, X: 0.5, Font: font); + FSharpOption<Color> plotBGColor = new FSharpOption<Color>(Color.fromKeyword(ColorKeyword.WhiteSmoke)); + Layout layout = Layout.init<IConvertible>(PaperBGColor: plotBGColor, PlotBGColor: plotBGColor, Title: t); + return chart.WithLayout(layout); + } + } +} From a0b4fa38caaac632e43148bbd553027fe69bd3d9 Mon Sep 17 00:00:00 2001 From: Alex Peck <alexpeck@microsoft.com> Date: Sat, 18 May 2024 14:48:52 -0700 Subject: [PATCH 3/3] rem paren --- BitFaster.Caching.ThroughputAnalysis/Exporter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BitFaster.Caching.ThroughputAnalysis/Exporter.cs b/BitFaster.Caching.ThroughputAnalysis/Exporter.cs index 280acccc..0c3456a6 100644 --- a/BitFaster.Caching.ThroughputAnalysis/Exporter.cs +++ b/BitFaster.Caching.ThroughputAnalysis/Exporter.cs @@ -131,13 +131,13 @@ public string MapTitle(Mode mode, int cacheSize) switch (mode) { case Mode.Read: - return $"Read throughput (100% cache hit) ({os}/{arch}/{fwk})"; + return $"Read throughput, 100% cache hit ({os}/{arch}/{fwk})"; case Mode.ReadWrite: return $"Read + Write throughput ({os}/{arch}/{fwk})"; case Mode.Update: return $"Update throughput ({os}/{arch}/{fwk})"; case Mode.Evict: - return $"Eviction throughput (100% cache miss) ({os}/{arch}/{fwk})"; + return $"Eviction throughput, 100% cache miss ({os}/{arch}/{fwk})"; default: return $"{mode} {cacheSize}"; }