| 1 | using System.Diagnostics; |
| 2 | using System.Globalization; |
| 3 | using System.Text; |
| 4 | using CasaField.Core; |
| 5 | |
| 6 | var store = args.Length > 0 |
| 7 | ? args[0] |
| 8 | : Path.GetFullPath(Path.Combine( |
| 9 | AppContext.BaseDirectory, |
| 10 | "..", "..", "..", "..", |
| 11 | "..", "casa-ontology-payload", "examples", "agent-stores", "research-agent-lab-v0")); |
| 12 | |
| 13 | var query = args.Length > 1 ? args[1] : "import knowledge delta"; |
| 14 | |
| 15 | if (!File.Exists(Path.Combine(store, "field_state.json"))) |
| 16 | { |
| 17 | Console.Error.WriteLine($"missing field_state in {store}"); |
| 18 | return 1; |
| 19 | } |
| 20 | |
| 21 | var sw = Stopwatch.StartNew(); |
| 22 | var first = CasaFieldHotPath.Run(store, query); |
| 23 | sw.Stop(); |
| 24 | var coldMs = sw.Elapsed.TotalMilliseconds; |
| 25 | |
| 26 | var times = new List<double>(30); |
| 27 | for (var i = 0; i < 30; i++) |
| 28 | { |
| 29 | sw.Restart(); |
| 30 | _ = CasaFieldHotPath.Run(store, query); |
| 31 | sw.Stop(); |
| 32 | times.Add(sw.Elapsed.TotalMilliseconds); |
| 33 | } |
| 34 | |
| 35 | times.Sort(); |
| 36 | var sb = new StringBuilder(); |
| 37 | sb.AppendLine("{"); |
| 38 | sb.AppendLine(" \"csharp\": {"); |
| 39 | var inv = CultureInfo.InvariantCulture; |
| 40 | sb.AppendLine($" \"cold_ms\": {coldMs.ToString("F3", inv)},"); |
| 41 | sb.AppendLine($" \"hot_loop_median_ms\": {times[times.Count / 2].ToString("F3", inv)},"); |
| 42 | sb.AppendLine($" \"hot_loop_p95_ms\": {times[(int)(times.Count * 0.95)].ToString("F3", inv)},"); |
| 43 | sb.AppendLine($" \"hot_loop_min_ms\": {times[0].ToString("F3", inv)},"); |
| 44 | sb.AppendLine($" \"first_field_version\": {first.FieldVersion},"); |
| 45 | sb.AppendLine($" \"first_stale\": {(first.Stale ? "true" : "false")},"); |
| 46 | sb.AppendLine($" \"first_concept_count\": {first.Decoded.ConceptIds.Count}"); |
| 47 | sb.AppendLine(" }"); |
| 48 | sb.AppendLine("}"); |
| 49 | Console.WriteLine(sb.ToString()); |
| 50 | return 0; |
| 51 | |