private static void TestSortingAlgorithmPerformance <T>(
            MethodToTest <T> methodToTest, ArrayHolder <T> arrayHolder, string algorithmName)
            where T : IComparable
        {
            string dataType = arrayHolder.SortedArray
                              .ToString()
                              .Split('.')[1];

            TimeSpan sortRandomElapsedTime =
                MeasureTimeToRunMethod(methodToTest, arrayHolder.RandomArray, RepetitionsCount);
            string randomTestDescription =
                string.Format("{0} with random {1}", algorithmName, dataType);

            ResultHelpers
            .PrintResults(sortRandomElapsedTime, randomTestDescription, RepetitionsCount);

            TimeSpan sortSortedElapsedTime =
                MeasureTimeToRunMethod(methodToTest, arrayHolder.SortedArray, RepetitionsCount);
            string sortedTestDescription =
                string.Format("{0} with sorted {1}", algorithmName, dataType);

            ResultHelpers
            .PrintResults(sortSortedElapsedTime, sortedTestDescription, RepetitionsCount);

            TimeSpan sortReversedElapsedTime =
                MeasureTimeToRunMethod(methodToTest, arrayHolder.ReversedSortedArray, RepetitionsCount);
            string reversedSortedTestDescription =
                string.Format("{0} with reversed sorted {1}", algorithmName, dataType);

            ResultHelpers
            .PrintResults(sortReversedElapsedTime, reversedSortedTestDescription, RepetitionsCount);
        }
Esempio n. 2
0
        public static TestRequest CreateRequestFor(MethodToTest methodToTest, NodeTestData testData)
        {
            switch (methodToTest)
            {
            case MethodToTest.GetBlockCount:
                return(new GetBlockCount());

            case MethodToTest.GetTransaction:
                return(new GetTransaction(testData.GetTxId(), null));

            case MethodToTest.GetRawTransaction:
                return(new GetRawTransaction(testData.GetTxId(), 1, null));

            case MethodToTest.DecodeRawTransaction:
                return(new DecodeRawTransaction(testData.GetRawHex(), null));

            case MethodToTest.ValidateAddress:
                return(new ValidateAddress(testData.GetAddress()));

            case MethodToTest.GetBlockHash:
                return(new GetBlockHash(testData.BlockCount));

            case MethodToTest.GetBlock:
                return(new GetBlock(testData.BlockHash, null));

            case MethodToTest.GetBalance:
                return(new GetBalance(null, null, null));

            case MethodToTest.ListUnspent:
                return(new ListUnspent(null, null, null, null, null));

            case MethodToTest.ListAddressGroupings:
                return(new ListAddressGroupings());

            case MethodToTest.SendMany:
                List <Tests.SendMany.Destination> destinations = new List <Tests.SendMany.Destination> {
                    new Tests.SendMany.Destination(testData.GetAddress(0), 1, false),
                    new Tests.SendMany.Destination(testData.GetAddress(1), 1, true),
                    new Tests.SendMany.Destination(testData.GetAddress(2), 1, true),
                };
                var    amounts     = destinations.ToDictionary(d => d.DestinationAddress, d => d.Amount);
                string jsonAmounts = JsonConvert.SerializeObject(amounts);

                var    subtractFees     = destinations.Where(dest => dest.SubtractFees).Select(dest => dest.DestinationAddress).Distinct().ToArray();
                string jsonSubtractFees = JsonConvert.SerializeObject(subtractFees);

                CallRequest.SendMany request = new CallRequest.SendMany(string.Empty, jsonAmounts, null, null, jsonSubtractFees, null, null, "UNSET");
                return(request);

            default:
                throw new Exception("Unknown method to test.");
            }
        }
Esempio n. 3
0
        public TestBase(MethodToTest methodToTest)
        {
            this.MethodToTest = methodToTest;

            this.DefaultRequest = new Dictionary <IRpcService, TestRequest>();
            foreach (var service in TestExecutor.Services)
            {
                this.DefaultRequest.Add(service, TestRequestFactory.CreateRequestFor(methodToTest, TestExecutor.TestData[service]));
            }

            this.options = PerformanceCollectorOptions.Default;
            this.Enabled = true;
        }
        private static TimeSpan MeasureTimeToRunMethod <T>(
            MethodToTest <T> method, T[] array, long repetitionsCount) where T : IComparable
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            for (long i = 0; i < repetitionsCount; i++)
            {
                method(array);
            }

            stopwatch.Stop();

            TimeSpan elapsedTime = stopwatch.Elapsed;

            return(elapsedTime);
        }