Exemplo n.º 1
0
        private Metric MeasureHot <T>(Func <Sample, bool> samplingPredicate, TextWriter status, string namePrefix, Func <Stream, T> prepInput, Action <IEngine, T> callMatcher)
        {
            var metric = new Metric($"{namePrefix} hot",
                                    new Axis("Pattern", Patterns),
                                    new Axis("Matcher", Matchers.Select(x => x.Item1)));
            var matchers = (from pattern in Patterns
                            from matcher in Matchers
                            select new { Item1 = new { Item1 = pattern, Item2 = matcher.Item1 }, Item2 = matcher.Item2().Compile(pattern) }).ToDictionary(x => x.Item1, x => x.Item2);

            status.Write($"Reading dataset..."); status.Flush();
            var stream = new ConcatenatedStream(Dataset);

            stream.Seek(0, SeekOrigin.Begin);
            var input = prepInput(stream);

            status.WriteLine($" done.");
            for (int i = 0; i < Patterns.Count; ++i)
            {
                status.WriteLine($"Pattern {i+1}/{Patterns.Count}");
                var pattern = Patterns[i];
                foreach (var entry in Matchers)
                {
                    var matcher = matchers[new { Item1 = pattern, Item2 = entry.Item1 }];
                    callMatcher(matcher, input);
                    var matchingTimeSample = SampleWhile(samplingPredicate, () => callMatcher(matcher, input));
                    metric.Add(matchingTimeSample, pattern, entry.Item1);
                }
            }
            return(metric);
        }
Exemplo n.º 2
0
        private Metric MeasureCold <T>(Func <Sample, bool> samplingPredicate, TextWriter status, string namePrefix, Func <Stream, T> prepInput, Action <IEngine, T> callMatcher)
        {
            var metric = new Metric($"{namePrefix} cold",
                                    new Axis("Pattern", Patterns),
                                    new Axis("Matcher", Matchers.Select(x => x.Item1)));
            var compilers = (from matcher in Matchers
                             select new { matcher.Item1, Item2 = matcher.Item2() }).ToDictionary(x => x.Item1, x => x.Item2);

            status.Write($"Reading dataset..."); status.Flush();
            var stream = new ConcatenatedStream(Dataset);

            stream.Seek(0, SeekOrigin.Begin);
            var input = prepInput(stream);

            status.WriteLine($" done.");
            foreach (var pattern in Patterns)
            {
                foreach (var matcher in Matchers)
                {
                    var compiler           = compilers[matcher.Item1];
                    var matchingTimeSample = SampleWhile(samplingPredicate, () => callMatcher(compiler.Compile(pattern), input));
                    metric.Add(matchingTimeSample, pattern, matcher.Item1);
                }
            }
            return(metric);
        }