private static long DoTest(IStringConcatenator concatenator, List <string> listForTest, int amountOfIterations) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Enumerable.Range(1, amountOfIterations).ToList().ForEach(i => { concatenator.Reset(); listForTest.ForEach(str => concatenator.DoConcatenation(str)); }); stopwatch.Stop(); return(stopwatch.ElapsedMilliseconds); }
/// <summary> /// Performs test using requested Concatenator. /// </summary> /// <param name="concatenator"></param> /// <param name="listForTest"></param> /// <param name="testsToRun"></param> /// <param name="amountOfIterations"></param> internal static void PerformTest(IStringConcatenator concatenator, List <string> listForTest, ushort testsToRun, int amountOfIterations) { Console.WriteLine(string.Format("Starting test: {0}, with {1} iterations. Repeating it {2} times.", concatenator.GetTestName(), amountOfIterations, testsToRun)); Console.Write("Test Results:"); List <long> results = Enumerable.Range(1, testsToRun).Select(e => { long elapsed = DoTest(concatenator, listForTest, amountOfIterations); Console.Write(string.Format(" {0} - {1} ms", e, elapsed)); return(elapsed); }).ToList(); Console.WriteLine(); Console.WriteLine(string.Format("Average Test time for list with {0} strings is: {1} ms.", listForTest.Count, AverageTestDuration(results))); Console.WriteLine(); }
/// <summary> /// Converts the list to a string. /// </summary> /// <param name="values">Values to convert to string.</param> /// <param name="culture">The CultureInfo to use as the current culture.</param> /// <param name="stringConcatenator">The concatenator which is used to build the string.</param> /// <returns>String representation of the given value list.</returns> public static string ConvertToStringRepresentation(this IEnumerable values, CultureInfo culture, IStringConcatenator stringConcatenator) { return(UniversalTypeConverter.ConvertToStringRepresentation(values, culture, stringConcatenator)); }
/// <summary> /// Converts the given value list to a string. /// </summary> /// <param name="values">Values to convert to string.</param> /// <param name="culture">The CultureInfo to use as the current culture.</param> /// <param name="stringConcatenator">The concatenator which is used to build the string.</param> /// <returns>String representation of the given value list.</returns> public static string ConvertToStringRepresentation(IEnumerable values, CultureInfo culture, IStringConcatenator stringConcatenator) { string[] stringValues = ConvertToEnumerable <string>(values) .UsingCulture(culture) .ToArray(); return(stringConcatenator.Concatenate(stringValues)); }
/// <summary> /// Converts the given value list to a string. /// </summary> /// <param name="values">Values to convert to string.</param> /// <param name="stringConcatenator">The concatenator which is used to build the string.</param> /// <returns>String representation of the given value list.</returns> public static string ConvertToStringRepresentation(IEnumerable values, IStringConcatenator stringConcatenator) { return(ConvertToStringRepresentation(values, DefaultCulture, stringConcatenator)); }