Пример #1
0
        public void MeasureUrl(string url)
        {
            var errors          = new List <Exception>();
            var bytesDownloaded = 0;
            var microSecs       = PerfUtils.Measure(() =>
            {
                try
                {
                    var download     = url.GetBytesFromUrl();
                    bytesDownloaded += download.Length;
                }
                catch (Exception ex)
                {
                    errors.Add(ex);
                }
            },
                                                    times: 1,
                                                    runForMs: 2000);

            if (errors.Count > 0)
            {
                errors.Map(x => x.Message).ToHashSet().PrintDump();
            }

            "{0} took avg of {1}us with and had {2} errors ({3} bytes downloaded)"
            .Print(url, microSecs, errors.Count, bytesDownloaded);
        }
Пример #2
0
        public void Compare_GetCmdBytes()
        {
            var res1 = GetCmdBytes1('$', 1234);
            var res2 = GetCmdBytes2('$', 1234);

            Debug.WriteLine(BitConverter.ToString(res1));
            Debug.WriteLine(BitConverter.ToString(res2));

            var ticks1 = PerfUtils.Measure(() => GetCmdBytes1('$', 2));
            var ticks2 = PerfUtils.Measure(() => GetCmdBytes2('$', 2));

            Debug.WriteLine(String.Format("{0} : {1} = {2}", ticks1, ticks2, ticks1 / (double)ticks2));
        }
        public void Compare_GetCmdBytes()
        {
            var res1 = GetCmdBytes1('$', 1234);
            var res2 = GetCmdBytes2('$', 1234);

            Console.WriteLine(BitConverter.ToString(res1));
            Console.WriteLine(BitConverter.ToString(res2));

            var ticks1 = PerfUtils.Measure(() => GetCmdBytes1('$', 2));
            var ticks2 = PerfUtils.Measure(() => GetCmdBytes2('$', 2));

            Console.WriteLine("{0} : {1} = {2}", ticks1, ticks2, ticks1 / ticks2);
        }
Пример #4
0
        public void Measure_unique_collections()
        {
            var set          = new HashSet <int>();
            var avgMicroSecs = PerfUtils.Measure(
                () => set.Add(rand.Next(0, 1000)), runForMs: 2000);

            "HashSet: {0}us".Print(avgMicroSecs);

            var list = new List <int>();

            avgMicroSecs = PerfUtils.Measure(
                () => {
                int i = rand.Next(0, 1000);
                if (!list.Contains(i))
                {
                    list.Add(i);
                }
            }, runForMs: 2000);

            "List: {0}us".Print(avgMicroSecs);
        }