public void CesilAuto() { var tr = TestData.GetTextReader(); var data = CesilUtils.Enumerate <SalesRecord>(tr, Options.Default); foreach (var record in data) { } }
private static void ExploreGitHistory(Options opts) { Console.WriteLine(nameof(ExploreGitHistory)); var repo = opts.GitRepo; var branch = opts.GitBranch; var hashes = opts.GitHashes; var name = $"{nameof(Cesil)}.{nameof(Benchmark)}-{Guid.NewGuid().ToString().Replace("-", "")}"; var dir = Path.Combine(Path.GetTempPath(), name); Directory.CreateDirectory(dir); var latest = Path.Combine(dir, "latest"); CloneRepository(latest, repo, branch); var allCommits = GetAllCommitHashes(latest); var selectedCommits = GetSelectedCommitHashes(hashes, allCommits); var benchmarkCommit = opts.GitBenchmarkHash; if (string.IsNullOrEmpty(benchmarkCommit)) { benchmarkCommit = allCommits.Last(); } if (!allCommits.Contains(benchmarkCommit)) { Console.Error.WriteLine($"Could not find benchmark commit {benchmarkCommit}"); Environment.Exit(-1); } var validCommits = GetValidCommits(latest, selectedCommits, benchmarkCommit); var resultsDir = Path.Combine(dir, "results"); var results = RunBenchmarksForCommits(opts, latest, resultsDir, validCommits, benchmarkCommit); var summary = SummarizeResults(results, validCommits); var csv = CesilUtils.WriteDynamicToString(summary); Console.WriteLine("Results"); Console.WriteLine("-------"); Console.WriteLine(csv); if (!string.IsNullOrEmpty(opts.OutputPath)) { File.WriteAllText(opts.OutputPath, csv); } Environment.Exit(0);
public void Enumerate() { using (var reader = new StringReader("Foo,Bar\r\nHello,World")) { var e = CesilUtils.Enumerate <_Enumerate>(reader); Assert.Collection( e, row => { Assert.Equal("Hello", row.Foo); Assert.Equal("World", row.Bar); } ); } // errors Assert.Throws <ArgumentNullException>(() => CesilUtils.Enumerate <_Enumerate>(default));
static Dictionary <string, List <BenchmarkResultRow> > RunBenchmarksForCommits(Options opts, string inDirectory, string outDirectory, IEnumerable <string> commits, string benchmarkCommit) { var ret = new Dictionary <string, List <BenchmarkResultRow> >(); Directory.CreateDirectory(outDirectory); foreach (var commit in commits) { var outFile = Path.Combine(outDirectory, $"{commit.Substring(0, 7)}.csv"); var newOpts = new Options { CompareToOtherLibraries = opts.CompareToOtherLibraries, ExcludeBenchmarks = opts.ExcludeBenchmarks, ExcludeCategories = opts.ExcludeCategories, IncludeBenchmarks = opts.IncludeBenchmarks, IncludeCategories = opts.IncludeCategories, Test = opts.Test, OutputPath = outFile }; var args = CommandLine.Parser.Default.FormatCommandLine(newOpts); // roll everything back var resetRes = RunCommand(inDirectory, "git reset --hard HEAD"); CheckCommandResult(resetRes); // get this specific commit var rollbackRes = RunCommand(inDirectory, $"git checkout {commit}"); CheckCommandResult(rollbackRes); // checkout the target version of the benchmark alongside this commit var benchmarkRes = RunCommand(inDirectory, $"git checkout {benchmarkCommit} -- .\\Cesil.Benchmark\\"); CheckCommandResult(benchmarkRes); // compile var compileRes = RunCommand(inDirectory, "dotnet build -c RELEASE"); CheckCommandResult(compileRes); // run the benchmarks (potentially with a retry) var runCommand = $"dotnet run -c RELEASE --no-build -- {args}"; var benchmarkDir = Path.Combine(inDirectory, "Cesil.Benchmark"); var retry = true; runBenchmark: var runRes = RunCommand(benchmarkDir, runCommand); if (runRes.ExitCode != 0) { Console.Error.WriteLine("An error occurred"); Console.Error.WriteLine(); Console.Error.WriteLine("Output"); Console.Error.WriteLine(runRes.Output); Console.Error.WriteLine(); if (!retry) { Console.Error.WriteLine("Skipping"); continue; } retry = false; Thread.Sleep(5_000); goto runBenchmark; } var results = CesilUtils.EnumerateFromFile <BenchmarkResultRow>(outFile); ret[commit] = results.ToList(); } return(ret); }
private IEnumerable <dynamic> GetRows(string rows, string type) { var toMakeDynamic = GetStaticRows(rows); switch (type) { case "Static": return(toMakeDynamic); case "Cesil": { string csvText; using (var writer = new StringWriter()) { using (var csv = StaticConfig.CreateWriter(writer)) { csv.WriteAll(toMakeDynamic); } csvText = writer.ToString(); } var opts = Options.CreateBuilder(Options.DynamicDefault).WithDynamicRowDisposal(DynamicRowDisposal.OnExplicitDispose).ToOptions(); var ret = CesilUtils.EnumerateDynamicFromString(csvText, opts).ToList(); return(ret); } case nameof(ExpandoObject): { var ret = new List <dynamic>(); foreach (var row in toMakeDynamic) { var expandoObj = new ExpandoObject(); var expando = (IDictionary <string, dynamic>)expandoObj; expando["Byte"] = row.Byte; expando["SByte"] = row.SByte; expando["Short"] = row.Short; expando["UShort"] = row.UShort; expando["Int"] = row.Int; expando["UInt"] = row.UInt; expando["Long"] = row.Long; expando["ULong"] = row.ULong; expando["Float"] = row.Float; expando["Double"] = row.Double; expando["Decimal"] = row.Decimal; expando["NullableByte"] = row.NullableByte; expando["NullableSByte"] = row.NullableSByte; expando["NullableShort"] = row.NullableShort; expando["NullableUShort"] = row.NullableUShort; expando["NullableInt"] = row.NullableInt; expando["NullableUInt"] = row.NullableUInt; expando["NullableLong"] = row.NullableLong; expando["NullableULong"] = row.NullableULong; expando["NullableFloat"] = row.NullableFloat; expando["NullableDouble"] = row.NullableDouble; expando["NullableDecimal"] = row.NullableDecimal; expando["String"] = row.String; expando["Char"] = row.Char; expando["NullableChar"] = row.NullableChar; expando["Guid"] = row.Guid; expando["NullableGuid"] = row.NullableGuid; expando["DateTime"] = row.DateTime; expando["DateTimeOffset"] = row.DateTimeOffset; expando["NullableDateTime"] = row.NullableDateTime; expando["NullableDateTimeOffset"] = row.NullableDateTimeOffset; expando["Uri"] = row.Uri; expando["Enum"] = row.Enum; expando["FlagsEnum"] = row.FlagsEnum; expando["NullableEnum"] = row.NullableEnum; expando["NullableFlagsEnum"] = row.NullableFlagsEnum; ret.Add(expandoObj); } return(ret); } case "Custom": { var ret = new List <dynamic>(); foreach (var row in toMakeDynamic) { var expandoObj = new FakeExpandoObject(); var expando = (IDictionary <string, dynamic>)expandoObj; expando["Byte"] = row.Byte; expando["SByte"] = row.SByte; expando["Short"] = row.Short; expando["UShort"] = row.UShort; expando["Int"] = row.Int; expando["UInt"] = row.UInt; expando["Long"] = row.Long; expando["ULong"] = row.ULong; expando["Float"] = row.Float; expando["Double"] = row.Double; expando["Decimal"] = row.Decimal; expando["NullableByte"] = row.NullableByte; expando["NullableSByte"] = row.NullableSByte; expando["NullableShort"] = row.NullableShort; expando["NullableUShort"] = row.NullableUShort; expando["NullableInt"] = row.NullableInt; expando["NullableUInt"] = row.NullableUInt; expando["NullableLong"] = row.NullableLong; expando["NullableULong"] = row.NullableULong; expando["NullableFloat"] = row.NullableFloat; expando["NullableDouble"] = row.NullableDouble; expando["NullableDecimal"] = row.NullableDecimal; expando["String"] = row.String; expando["Char"] = row.Char; expando["NullableChar"] = row.NullableChar; expando["Guid"] = row.Guid; expando["NullableGuid"] = row.NullableGuid; expando["DateTime"] = row.DateTime; expando["DateTimeOffset"] = row.DateTimeOffset; expando["NullableDateTime"] = row.NullableDateTime; expando["NullableDateTimeOffset"] = row.NullableDateTimeOffset; expando["Uri"] = row.Uri; expando["Enum"] = row.Enum; expando["FlagsEnum"] = row.FlagsEnum; expando["NullableEnum"] = row.NullableEnum; expando["NullableFlagsEnum"] = row.NullableFlagsEnum; ret.Add(expandoObj); } return(ret); } default: throw new Exception(); } }