/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
tests/MassTransit.Benchmark/Analytics.cs
62 строки
2 KB
Chris Patterson
Added Kafka to benchmark to test throughput/latency.
24 дек 2022, 04:26
24 дек 2022, 04:26
20d61f6
Код
Авторство
О чём код?
namespace MassTransitBenchmark { using System; using System.Collections.Generic; using System.Linq; public static class Analytics { public static double? Median<TColl, TValue>(this IEnumerable<TColl> source, Func<TColl, TValue> selector) where TValue : struct { return source.Select(selector).Median(); } public static double? Percentile<TColl, TValue>(this IEnumerable<TColl> source, Func<TColl, TValue> selector, int percentile = 95) where TValue : struct { return source.Select(selector).Percentile(percentile); } public static double? Median<T>(this IEnumerable<T> source) where T : struct { var count = source.Count(); if (count == 0) return null; source = source.OrderBy(n => n); var midpoint = count / 2; if (count % 2 == 0) { return (Convert.ToDouble(source.ElementAt(midpoint - 1)) + Convert.ToDouble(source.ElementAt(midpoint))) / 2.0; } return Convert.ToDouble(source.ElementAt(midpoint)); } public static double? Percentile<T>(this IEnumerable<T> source, int percentile) where T : struct { var count = source.Count(); if (count == 0) return null; source = source.OrderBy(n => n); var point = count * percentile / 100; if (count % 2 == 0) { return (Convert.ToDouble(source.ElementAt(point - 1)) + Convert.ToDouble(source.ElementAt(point))) / 2.0; } return Convert.ToDouble(source.ElementAt(point)); } } }