/** * testIterationOfStringListWithIterator. * * @return */ public static long testIterationOfClassWith1intArrayListWithIterator() { ClassWith1intb classWith1int = new ClassWith1intb(); IList list = new ArrayList(SIZE); for (int j = SIZE; j != 0; j--) { list.Add(classWith1int); } int count = 0; DateTime start = DateTime.Now; for (int i = TESTS_LIST; i != 0; i--) { for (IEnumerator enumerator = list.GetEnumerator(); enumerator.MoveNext(); ) { ClassWith1intb classWith1intb = (ClassWith1intb)enumerator.Current; // Write to force cpp not to optimize the code, never executed if (i % 2 == 2) { classWith1intb.Int1 = i; } count += classWith1intb.Int1; } } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], Iteration of " + TESTS_LIST + " ArrayList(" + SIZE + ") With Iterator for (IEnumerator enumerator = list.GetEnumerator() enumerator.MoveNext() ) iterator.hasNext() ) count += ((ClassWith1intb)enumerator.Current).Int1 , count=" + count + ", snapshot time," + executionTime.TotalMilliseconds); return (long)executionTime.TotalMilliseconds; }
/** * testIterationOfStringListWithReverseLoopDifferentZeroDecrementInTest. * * @return */ public static long testIterationOfClassWith1intArrayListWithReverseLoopDifferentZeroDecrementInTest() { ClassWith1intb classWith1int = new ClassWith1intb(); IList list = new ArrayList(SIZE); for (int j = SIZE; j != 0; j--) { list.Add(classWith1int); } int count = 0; DateTime start = DateTime.Now; for (int i = TESTS_LIST; i != 0; i--) { for (int k = list.Count; k-- != 0; ) { // Write to force cpp not to optimize the code, never executed if (k % 2 == 2) { ((ClassWith1intb)list[k]).Int1 = k; } count += ((ClassWith1intb)list[k]).Int1; } } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], Iteration of " + TESTS_LIST + " ArrayList(" + SIZE + ") With Reverse Loop Different Zero Decrement in Test for (int k = list.Count k-- != 0 ) count += ((ClassWith1intb)list[k]).Int1 ,count=" + count + ", snapshot time," + executionTime.TotalMilliseconds); return (long)executionTime.TotalMilliseconds; }
/** * testCreationOfStringArray. * * @return */ public static long testCreationOfClassWith1intArray() { DateTime start = DateTime.Now; for (int i = TESTS_LIST; i != 0; i--) { ClassWith1intb[] list = new ClassWith1intb[SIZE]; } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], Creation of " + TESTS_LIST + " ClassWith1intArray[" + SIZE + "] ClassWith1intb[] list = new ClassWith1intb[SIZE] ,, snapshot time," + executionTime.TotalMilliseconds); return (long) executionTime.TotalMilliseconds; }
/** * testCreationOfStringList. * * @return */ public static long testCreationOfClassWith1intList() { ClassWith1intb classWith1int = new ClassWith1intb(); DateTime start = DateTime.Now; for (int i = TESTS_LIST; i != 0; i--) { List<ClassWith1intb> list = new List<ClassWith1intb>(SIZE); for (int j = SIZE; j != 0; j--) list.Add(classWith1int); } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], Creation of " + TESTS_LIST + " List<ClassWith1int>(" + SIZE + ") final List<ClassWith1int> list = new ArrayList<ClassWith1int>(SIZE) for (int j = SIZE j != 0 j--) list.add(classWith1int) ,, snapshot time," + executionTime.TotalMilliseconds); return (long) executionTime.TotalMilliseconds; }
/** * testCreationOfStringList. * * @return */ public static long testCreationAndAddElementsToClassWith1intList() { ClassWith1intb classWith1int = new ClassWith1intb(); DateTime start = DateTime.Now; for (int i = TESTS_LIST; i != 0; i--) { List<ClassWith1intb> list = new List<ClassWith1intb>(SIZE); for (int j = SIZE; j != 0; j--) list.Add(classWith1int); } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], Creation of " + TESTS_LIST + " and Add " + SIZE + " Elements to List<ClassWith1intb>[" + SIZE + "] for (int j = SIZE j-- != 0 ) List<ClassWith1intb> list = new List<ClassWith1intb>(SIZE) list.Add(classWith1int) ,, snapshot time," + executionTime.TotalMilliseconds); return (long)executionTime.TotalMilliseconds; }
/** * testCreationAndAddElementsToStringArray. * * @return */ public static long testCreationAndPutElementsInClassWith1intMap() { ClassWith1intb classWith1int = new ClassWith1intb(); DateTime start = DateTime.Now; for (int i = TESTS_MAP; i-- != 0; ) { Hashtable map = new Hashtable(SIZE); for (int j = SIZE; j != 0; j--) map.Add(j, classWith1int); } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], Creation of " + TESTS_MAP + " And Put " + SIZE + " Elements for (int j = SIZE j != 0 j--) Hashtable map = new Hashtable(SIZE) map.Add(j classWith1int) ,, snapshot time," + executionTime.TotalMilliseconds); return (long)executionTime.TotalMilliseconds; }
/** * testCopyData. * * @return */ public static long testCopyDataOptimized() { ClassWith1intb[] src = new ClassWith1intb[SIZE]; ClassWith1intb[] dest = new ClassWith1intb[SIZE]; for (int i = SIZE; i-- != 0; ) { ClassWith1intb classWith1int = new ClassWith1intb(); classWith1int.Int1 = RandomizerCollection.getRandomValue(100000); src[i] = classWith1int; } DateTime start = DateTime.Now; for (int i = NB_COPY_DATA_TESTS; i != 0; i--) { src.CopyTo(dest, 0); } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], Copy data Optimized from an array to an array " + SIZE + ",, snapshot time," + executionTime.TotalMilliseconds); return (long)executionTime.TotalMilliseconds; }
/** * testIterationOfStringArrayWithTryCatch. * * @return */ public static long testIterationOfClassWith1intArrayWithTryCatch() { ClassWith1intb classWith1int = new ClassWith1intb(); ClassWith1intb[] list = new ClassWith1intb[SIZE]; for (int j = SIZE; j != 0; j--) { list[j - 1] = classWith1int; } int count = 0; DateTime start = DateTime.Now; for (int i = TESTS_LIST; i != 0; i--) { try { for (int k = 0; ; k++) { // Write to force cpp not to optimize the code, never executed if (k % 2 == 2) { list[k].Int1 = k; } count += list[k].Int1; } } catch (Exception e) { // } } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], Iteration of " + TESTS_LIST + " ClassWith1intArray[" + SIZE + "] With Try Catch try{for (int k = 0 k++) count += list[k].Length } catch (ArrayIndexOutOfBoundsException x){}, count=" + count + ", snapshot time," + executionTime.TotalMilliseconds); return (long) executionTime.TotalMilliseconds; }
/** * testPutElementsInStringDictionary. * * @return */ public static long testPutElementsInClassWith1intDictionary() { ClassWith1intb classWith1int = new ClassWith1intb(); Dictionary<int, ClassWith1intb> map = new Dictionary<int, ClassWith1intb>(SIZE); DateTime start = DateTime.Now; for (int i = TESTS_MAP; i-- != 0; ) { for (int j = SIZE; j != 0; j--) map.Add(j, classWith1int); map.Clear(); } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], " + TESTS_MAP + " Tests of Put " + SIZE + " Elements Dictionary<int ClassWith1int>(" + SIZE + ") for (int j = SIZE j != 0 j--) map.Add(j classWith1int) ,, snapshot time," + executionTime.TotalMilliseconds); return (long)executionTime.TotalMilliseconds; }
/** * testCreationOfStringList. * * @return */ public static long testAddElementsToClassWith1intArrayList() { ClassWith1intb classWith1int = new ClassWith1intb(); IList list = new ArrayList(SIZE); DateTime start = DateTime.Now; for (int i = TESTS_LIST; i != 0; i--) { for (int j = SIZE; j != 0; j--) list.Add(classWith1int); list.Clear(); } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], " + TESTS_LIST + " Tests of Add " + SIZE + " Elements to ArrayList[" + SIZE + " for (int j = SIZE j != 0 j--) list.Add(classWith1int) list.Clear() ,, snapshot time," + executionTime.TotalMilliseconds); return (long)executionTime.TotalMilliseconds; }
/** * testCreationOfStringMap. * * @return */ public static long testIterationOfClassWith1intMap() { ClassWith1intb classWith1int = new ClassWith1intb(); Hashtable map = new Hashtable(SIZE); for (int j = SIZE; j != 0; j--) { map.Add(j, classWith1int); } DateTime start = DateTime.Now; for (int i = TESTS_READ_MAP; i-- != 0;) { for (int j = SIZE; j != 0; j--) { ClassWith1intb s = (ClassWith1intb) map[j]; } } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], Iteration of " + TESTS_MAP + " Hashtable(" + SIZE + ") for (int j = SIZE j != 0 j--) ClassWith1intb s = (ClassWith1intb) map[j] ,, snapshot time," + executionTime.TotalMilliseconds); return (long) executionTime.TotalMilliseconds; }
/** * testIterationOfStringListWithIterator. * * @return */ public static long testIterationOfClassWith1intListWithForwardLoop() { ClassWith1intb classWith1int = new ClassWith1intb(); List<ClassWith1intb> list = new List<ClassWith1intb>(SIZE); for (int j = SIZE; j != 0; j--) { list.Add(classWith1int); } int count = 0; DateTime start = DateTime.Now; for (int i = TESTS_LIST; i != 0; i--) { for (int k = 0; k < list.Count; k++) { // Write to force cpp not to optimize the code, never executed /*if (k % 2 == 2) { list[k].Int1 = k; }*/ count += list[k].Int1; } } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], Iteration of " + TESTS_LIST + " List<ClassWith1intb>(" + SIZE + ") With Forward Loop for (int k = 0; k < list.Count k++) count += list[k].Int1 , count=" + count + ", snapshot time," + executionTime.TotalMilliseconds); return (long) executionTime.TotalMilliseconds; }
/** * testCreationOfStringMap. * * @return */ public static long testIterationOfClassWith1intDictionaryWithoutTryCatch() { ClassWith1intb classWith1int = new ClassWith1intb(); Dictionary<int, ClassWith1intb> map = new Dictionary<int, ClassWith1intb>(SIZE); for (int j = SIZE; j != 0; j--) { map.Add(j, classWith1int); } DateTime start = DateTime.Now; for (int i = TESTS_READ_MAP; i-- != 0; ) { for (int j = SIZE; j != 0; j--) { if (map.ContainsKey(j)) { ClassWith1intb s = (ClassWith1intb) map[j]; } } } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], Iteration of " + TESTS_MAP + " Dictionary<int ClassWith1intb>(" + SIZE + ") for (int j = SIZE j != 0 j--) if (map.ContainsKey(j)) ClassWith1intb s = (ClassWith1intb) map[j] ,, snapshot time," + executionTime.TotalMilliseconds); return (long)executionTime.TotalMilliseconds; }
/** * testIterationOfStringListWithTryCatch. * * @return */ public static long testIterationOfClassWith1intArrayListWithTryCatch() { ClassWith1intb classWith1int = new ClassWith1intb(); IList list = new ArrayList(SIZE); for (int j = SIZE; j-- != 0; ) { list.Add(classWith1int); } int count = 0; DateTime start = DateTime.Now; for (int i = TESTS_LIST; i != 0; i--) { try { for (int k = 0; ; k++) { // Write to force cpp not to optimize the code, never executed if (k % 2 == 2) { ((ClassWith1intb) list[k]).Int1 = k; } count += ((ClassWith1intb)list[k]).Int1; } } catch (Exception e) { // } } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], Iteration of " + TESTS_LIST + " ArrayList(" + SIZE + ") With Try Catch try{ for (int k = 0 k++) count += ((ClassWith1intb)list[k]).Length } catch (Exception x){}, count=" + count + ", snapshot time," + executionTime.TotalMilliseconds); return (long)executionTime.TotalMilliseconds; }
/** * testCreationOfStringArray. * * @return */ public static long testCreationAndAddElementsToClassWith1intArray() { ClassWith1intb classWith1int = new ClassWith1intb(); DateTime start = DateTime.Now; for (int i = TESTS_LIST; i != 0; i--) { ClassWith1intb[] list = new ClassWith1intb[SIZE]; for (int j = SIZE; j-- != 0; ) list[j] = classWith1int; } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], Creation of " + TESTS_LIST + " and Add " + SIZE + " Elements to ClassWith1intArray[" + SIZE + "] for (int j = SIZE j != 0 j--) ClassWith1intb[] list = new ClassWith1intb[SIZE] list[j] = classWith1int ,, snapshot time," + executionTime.TotalMilliseconds); return (long)executionTime.TotalMilliseconds; }
/** * testIterationOfStringArrayWithForGeneric. * * @return */ public static long testIterationOfClassWith1intArrayWithForGeneric() { ClassWith1intb classWith1int = new ClassWith1intb(); ClassWith1intb[] list = new ClassWith1intb[SIZE]; for (int j = SIZE; j != 0; j--) { list[j - 1] = classWith1int; } int count = 0; DateTime start = DateTime.Now; for (int i = TESTS_LIST; i != 0; i--) { foreach (ClassWith1intb s in list) { // Write to force cpp not to optimize the code, never executed if (i % 2 == 2) { list[i].Int1 = i; } count += s.Int1; } } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], Iteration of " + TESTS_LIST + " ClassWith1intArray[" + SIZE + "] With For Generic for (final ClassWith1int s : list) count += s.Int1 , count=" + count + ", snapshot time," + executionTime.TotalMilliseconds); return (long) executionTime.TotalMilliseconds; }
/** * testIterationOfStringArrayWithReverseLoopDifferentZero. * * @return */ public static long testIterationOfClassWith1intArrayWithReverseLoopDifferentZero() { ClassWith1intb classWith1int = new ClassWith1intb(); ClassWith1intb[] list = new ClassWith1intb[SIZE]; for (int j = SIZE; j != 0; j--) { list[j - 1] = classWith1int; } int count = 0; DateTime start = DateTime.Now; for (int i = TESTS_LIST; i != 0; i--) { for (int k = list.Length; k != 0; k--) { // Write to force cpp not to optimize the code, never executed if (k % 2 == 2) { list[k].Int1 = k; } count += list[k - 1].Int1; } } DateTime end = DateTime.Now; TimeSpan executionTime = end - start; Console.WriteLine("[CollectionTest], Iteration of " + TESTS_LIST + " ClassWith1intArray[" + SIZE + "] With Reverse Loop Different Zero for (int k = list.length k != 0 k--) count = count += list[k - 1].Int1 ,, snapshot time," + executionTime.TotalMilliseconds); return (long) executionTime.TotalMilliseconds; }