예제 #1
0
        public void UniformReservoir_RecordsUserValue()
        {
            UniformReservoir reservoir = new UniformReservoir(100);

            reservoir.Update(2L, "B");
            reservoir.Update(1L, "A");

            reservoir.GetSnapshot().MinUserValue.Should().Be("A");
            reservoir.GetSnapshot().MaxUserValue.Should().Be("B");
        }
예제 #2
0
        public void can_records_user_value()
        {
            var reservoir = new UniformReservoir(100);

            reservoir.Update(2L, "B");
            reservoir.Update(1L, "A");

            reservoir.GetSnapshot().MinUserValue.Should().Be("A");
            reservoir.GetSnapshot().MaxUserValue.Should().Be("B");
        }
예제 #3
0
        public void UniformReservoir_Of100OutOf1000Elements()
        {
            UniformReservoir reservoir = new UniformReservoir(100);

            for (int i = 0; i < 1000; i++)
            {
                reservoir.Update(i);
            }

            reservoir.Size.Should().Be(100);
            reservoir.GetSnapshot().Size.Should().Be(100);
            reservoir.GetSnapshot().Values.Should().OnlyContain(v => 0 <= v && v < 1000);
        }
예제 #4
0
        public void of_100_out_of_1000_elements()
        {
            var reservoir = new UniformReservoir(100);

            for (var i = 0; i < 1000; i++)
            {
                reservoir.Update(i);
            }

            reservoir.Size.Should().Be(100);
            reservoir.GetSnapshot().Size.Should().Be(100);
            reservoir.GetSnapshot().Values.Should().OnlyContain(v => 0 <= v && v < 1000);
        }
예제 #5
0
        public void UniformResevoir()
        {
            var reservoir = new UniformReservoir(Constants.ReservoirSampling.DefaultSampleSize);

            foreach (var sample in _samples)
            {
                reservoir.Update((long)sample);
            }

            var snapshot = reservoir.GetSnapshot();

            //TODO: Assert snapshot
            //snapshot.AssertValues(_samples);
        }
예제 #6
0
        static void Main(string[] args)
        {
            var options = new Options();

            if (!Parser.Default.ParseArguments(args, options, (t, o) => { target = t; targetOptions = o as CommonOptions; }))
            {
                Console.WriteLine(new CommonOptions().GetUsage());
                Environment.Exit(CommandLine.Parser.DefaultExitCodeFail);
            }

            BenchmarkRunner.DefaultTotalSeconds = targetOptions.Seconds;
            BenchmarkRunner.DefaultMaxThreads   = targetOptions.MaxThreads;

            //Metric.Config.WithHttpEndpoint("http://localhost:1234/");

            switch (target)
            {
            case "noop":
                BenchmarkRunner.Run("Noop", () => { });
                break;

            case "counter":
                var counter = new CounterMetric();
                BenchmarkRunner.Run("Counter", () => counter.Increment());
                break;

            case "meter":
                var meter = new MeterMetric();
                BenchmarkRunner.Run("Meter", () => meter.Mark());
                break;

            case "histogram":
                var histogram = new HistogramMetric();
                BenchmarkRunner.Run("Histogram", () => histogram.Update(137));
                break;

            case "timer":
                var timer = new TimerMetric();
                BenchmarkRunner.Run("Timer", () => timer.Record(1, TimeUnit.Milliseconds));
                break;

            case "hdrtimer":
                var hdrTimer = new TimerMetric(new HdrHistogramReservoir());
                BenchmarkRunner.Run("HDR Timer", () => hdrTimer.Record(1, TimeUnit.Milliseconds));
                break;

            case "ewma":
                var ewma = EWMA.OneMinuteEWMA();
                BenchmarkRunner.Run("EWMA", () => ewma.Update(1));
                break;

            case "edr":
                var edr = new ExponentiallyDecayingReservoir();
                BenchmarkRunner.Run("EDR", () => edr.Update(1));
                break;

            case "hdr":
                var hdrReservoir = new HdrHistogramReservoir();
                BenchmarkRunner.Run("HDR Recorder", () => hdrReservoir.Update(1));
                break;

            case "uniform":
                var uniform = new UniformReservoir();
                BenchmarkRunner.Run("Uniform", () => uniform.Update(1));
                break;

            case "sliding":
                var sliding = new SlidingWindowReservoir();
                BenchmarkRunner.Run("Sliding", () => sliding.Update(1));
                break;

            case "timerimpact":
                var load = new WorkLoad();
                BenchmarkRunner.Run("WorkWithoutTimer", () => load.DoSomeWork(), iterationsChunk: 10);
                BenchmarkRunner.Run("WorkWithTimer", () => load.DoSomeWorkWithATimer(), iterationsChunk: 10);
                break;
            }
        }
        public void UniformReservoir()
        {
            var reservoir = new UniformReservoir(SampleSize);

            Run(reservoir);
        }