Created
May 29, 2020 14:43
-
-
Save rr-codes/e9d489243a2e7f8e295b4eb47978da8c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| using System; | |
| using System.Collections.Generic; | |
| using System.IO; | |
| using System.Linq; | |
| using System.Text.RegularExpressions; | |
| using Newtonsoft.Json; | |
| namespace ConsoleApplication1 | |
| { | |
| public struct Benchmark | |
| { | |
| private static readonly Regex FunctionNameRegex = new Regex(".{3}_(.*)_mean"); | |
| [JsonProperty(PropertyName = "name")] | |
| public string Name; | |
| [JsonProperty(PropertyName = "aggregate_name")] | |
| public string AggregateName; | |
| [JsonProperty(PropertyName = "cpu_time")] | |
| public double CpuTime; | |
| public string FunctionName => FunctionNameRegex.Match(Name).Groups[1].ToString(); | |
| } | |
| public struct Report | |
| { | |
| [JsonProperty(PropertyName = "context")] | |
| public object Context; | |
| [JsonProperty(PropertyName = "benchmarks")] | |
| public IEnumerable<Benchmark> Benchmarks; | |
| } | |
| internal class Program | |
| { | |
| public static void Main(string[] args) | |
| { | |
| var text = File.ReadAllText(@"C:\Users\rir\Documents\out3.json"); | |
| var json = JsonConvert.DeserializeObject<Report>(text); | |
| var means = json.Benchmarks | |
| .Where(b => b.AggregateName == "mean") | |
| .GroupBy(b => b.FunctionName) | |
| .Select(group => $"{group.Key}, {group.First().CpuTime}, {group.Last().CpuTime}") | |
| .Aggregate((a, b) => $"{a}\n{b}"); | |
| Console.WriteLine(means); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment