Created
April 15, 2011 03:21
-
-
Save saga/921076 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable | |
class CFromList : List<int>{} | |
// public class ArrayList : IList, ICollection, IEnumerable, ICloneable | |
class CFromArrayList : ArrayList{} | |
public partial class Form1 : Form | |
{ | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
CFromList list1 = new CFromList(); | |
CFromArrayList list2 = new CFromArrayList(); | |
//////////////////////////// | |
HighResolutionTimer timera = new HighResolutionTimer(); | |
for (int i = 0; i < 100000; i++) | |
{ | |
list1.Add(i - 99999); | |
} | |
Int64 reta = timera.Stop(); | |
//////////////////////////// | |
HighResolutionTimer timerb = new HighResolutionTimer(); | |
for (int i = 0; i < 100000; i++) | |
{ | |
list2.Add(i - 99999); | |
} | |
Int64 retb = timerb.Stop(); | |
//////////////////////////// | |
int index = 0; | |
HighResolutionTimer timer1 = new HighResolutionTimer(); | |
foreach (int elem1 in list1) | |
{ | |
list1[index++] = elem1 + 99; | |
} | |
Int64 ret1 = timer1.Stop(); | |
//////////////////////////// | |
index = 0; | |
HighResolutionTimer timer2 = new HighResolutionTimer(); | |
foreach (int elem2 in list2) | |
{ | |
list2[index++] = elem2 + 99; | |
} | |
Int64 ret2 = timer2.Stop(); | |
//////////////////////////// | |
} | |
} | |
/////////////////////////////////////////////////////// | |
// result from ILSpy | |
CFromList cFromList = new CFromList(); | |
CFromArrayList cFromArrayList = new CFromArrayList(); | |
HighResolutionTimer highResolutionTimer = new HighResolutionTimer(); | |
for (int i = 0; i < 100000; i++) | |
{ | |
cFromList.Add(i - 99999); | |
} | |
long num = highResolutionTimer.Stop(); | |
HighResolutionTimer highResolutionTimer2 = new HighResolutionTimer(); | |
for (int i = 0; i < 100000; i++) | |
{ | |
cFromArrayList.Add(i - 99999); | |
} | |
long num2 = highResolutionTimer2.Stop(); | |
int num3 = 0; | |
HighResolutionTimer highResolutionTimer3 = new HighResolutionTimer(); | |
foreach (int current in cFromList) | |
{ | |
cFromList[num3++] = current + 99; | |
} | |
long num4 = highResolutionTimer3.Stop(); | |
num3 = 0; | |
HighResolutionTimer highResolutionTimer4 = new HighResolutionTimer(); | |
IEnumerator enumerator2 = cFromArrayList.GetEnumerator(); | |
try | |
{ | |
while (enumerator2.MoveNext()) | |
{ | |
int num5 = (int)enumerator2.Current; | |
cFromArrayList[num3++] = num5 + 99; | |
} | |
} | |
finally | |
{ | |
IDisposable disposable = enumerator2 as IDisposable; | |
if (disposable != null) | |
{ | |
disposable.Dispose(); | |
} | |
} | |
long num6 = highResolutionTimer4.Stop(); | |
////////////////////////////////////////////////// | |
// result from ILSpy IL format | |
IL_0000: nop | |
IL_0001: newobj instance void WindowsFormsApplication1.CFromList::.ctor() | |
IL_0006: stloc.0 | |
IL_0007: newobj instance void WindowsFormsApplication1.CFromArrayList::.ctor() | |
IL_000c: stloc.1 | |
IL_000d: newobj instance void WindowsFormsApplication1.HighResolutionTimer::.ctor() | |
IL_0012: stloc.2 | |
IL_0013: ldc.i4.0 | |
IL_0014: stloc.3 | |
IL_0015: br.s IL_002b | |
// loop start (head: IL_002b) | |
IL_0017: nop | |
IL_0018: ldloc.0 | |
IL_0019: ldloc.3 | |
IL_001a: ldc.i4 99999 | |
IL_001f: sub | |
IL_0020: callvirt instance void [mscorlib]System.Collections.Generic.List`1<int32>::Add(!0) | |
IL_0025: nop | |
IL_0026: nop | |
IL_0027: ldloc.3 | |
IL_0028: ldc.i4.1 | |
IL_0029: add | |
IL_002a: stloc.3 | |
IL_002b: ldloc.3 | |
IL_002c: ldc.i4 100000 | |
IL_0031: clt | |
IL_0033: stloc.s 17 | |
IL_0035: ldloc.s 17 | |
IL_0037: brtrue.s IL_0017 | |
// end loop | |
IL_0039: ldloc.2 | |
IL_003a: callvirt instance int64 WindowsFormsApplication1.HighResolutionTimer::Stop() | |
IL_003f: stloc.s 4 | |
IL_0041: newobj instance void WindowsFormsApplication1.HighResolutionTimer::.ctor() | |
IL_0046: stloc.s 5 | |
IL_0048: ldc.i4.0 | |
IL_0049: stloc.3 | |
IL_004a: br.s IL_0065 | |
// loop start (head: IL_0065) | |
IL_004c: nop | |
IL_004d: ldloc.1 | |
IL_004e: ldloc.3 | |
IL_004f: ldc.i4 99999 | |
IL_0054: sub | |
IL_0055: box int32 | |
IL_005a: callvirt instance int32 [mscorlib]System.Collections.ArrayList::Add(object) | |
IL_005f: pop | |
IL_0060: nop | |
IL_0061: ldloc.3 | |
IL_0062: ldc.i4.1 | |
IL_0063: add | |
IL_0064: stloc.3 | |
IL_0065: ldloc.3 | |
IL_0066: ldc.i4 100000 | |
IL_006b: clt | |
IL_006d: stloc.s 17 | |
IL_006f: ldloc.s 17 | |
IL_0071: brtrue.s IL_004c | |
// end loop | |
IL_0073: ldloc.s 5 | |
IL_0075: callvirt instance int64 WindowsFormsApplication1.HighResolutionTimer::Stop() | |
IL_007a: stloc.s 6 | |
IL_007c: ldc.i4.0 | |
IL_007d: stloc.s 7 | |
IL_007f: newobj instance void WindowsFormsApplication1.HighResolutionTimer::.ctor() | |
IL_0084: stloc.s 8 | |
IL_0086: nop | |
IL_0087: ldloc.0 | |
IL_0088: callvirt instance valuetype [mscorlib]System.Collections.Generic.List`1/Enumerator<!0> [mscorlib]System.Collections.Generic.List`1<int32>::GetEnumerator() | |
IL_008d: stloc.s 18 | |
.try { | |
IL_008f: br.s IL_00af | |
// loop start (head: IL_00af) | |
IL_0091: ldloca.s 18 | |
IL_0093: call instance !0 [mscorlib]System.Collections.Generic.List`1/Enumerator<int32>::get_Current() | |
IL_0098: stloc.s 9 | |
IL_009a: nop | |
IL_009b: ldloc.0 | |
IL_009c: ldloc.s 7 | |
IL_009e: dup | |
IL_009f: ldc.i4.1 | |
IL_00a0: add | |
IL_00a1: stloc.s 7 | |
IL_00a3: ldloc.s 9 | |
IL_00a5: ldc.i4.s 99 | |
IL_00a7: add | |
IL_00a8: callvirt instance void [mscorlib]System.Collections.Generic.List`1<int32>::set_Item(int32, !0) | |
IL_00ad: nop | |
IL_00ae: nop | |
IL_00af: ldloca.s 18 | |
IL_00b1: call instance bool [mscorlib]System.Collections.Generic.List`1/Enumerator<int32>::MoveNext() | |
IL_00b6: stloc.s 17 | |
IL_00b8: ldloc.s 17 | |
IL_00ba: brtrue.s IL_0091 | |
// end loop | |
IL_00bc: leave.s IL_00cd | |
} // end .try | |
finally { | |
IL_00be: ldloca.s 18 | |
IL_00c0: constrained. valuetype [mscorlib]System.Collections.Generic.List`1/Enumerator<int32> | |
IL_00c6: callvirt instance void [mscorlib]System.IDisposable::Dispose() | |
IL_00cb: nop | |
IL_00cc: endfinally | |
} // end handler | |
IL_00cd: nop | |
IL_00ce: ldloc.s 8 | |
IL_00d0: callvirt instance int64 WindowsFormsApplication1.HighResolutionTimer::Stop() | |
IL_00d5: stloc.s 10 | |
IL_00d7: ldc.i4.0 | |
IL_00d8: stloc.s 7 | |
IL_00da: newobj instance void WindowsFormsApplication1.HighResolutionTimer::.ctor() | |
IL_00df: stloc.s 11 | |
IL_00e1: nop | |
IL_00e2: ldloc.1 | |
IL_00e3: callvirt instance class [mscorlib]System.Collections.IEnumerator [mscorlib]System.Collections.ArrayList::GetEnumerator() | |
IL_00e8: stloc.s 19 | |
.try { | |
IL_00ea: br.s IL_0114 | |
// loop start (head: IL_0114) | |
IL_00ec: ldloc.s 19 | |
IL_00ee: callvirt instance object [mscorlib]System.Collections.IEnumerator::get_Current() | |
IL_00f3: unbox.any int32 | |
IL_00f8: stloc.s 12 | |
IL_00fa: nop | |
IL_00fb: ldloc.1 | |
IL_00fc: ldloc.s 7 | |
IL_00fe: dup | |
IL_00ff: ldc.i4.1 | |
IL_0100: add | |
IL_0101: stloc.s 7 | |
IL_0103: ldloc.s 12 | |
IL_0105: ldc.i4.s 99 | |
IL_0107: add | |
IL_0108: box int32 | |
IL_010d: callvirt instance void [mscorlib]System.Collections.ArrayList::set_Item(int32, object) | |
IL_0112: nop | |
IL_0113: nop | |
IL_0114: ldloc.s 19 | |
IL_0116: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() | |
IL_011b: stloc.s 17 | |
IL_011d: ldloc.s 17 | |
IL_011f: brtrue.s IL_00ec | |
// end loop | |
IL_0121: leave.s IL_0140 | |
} // end .try | |
finally { | |
IL_0123: ldloc.s 19 | |
IL_0125: isinst class [mscorlib]System.IDisposable | |
IL_012a: stloc.s 20 | |
IL_012c: ldloc.s 20 | |
IL_012e: ldnull | |
IL_012f: ceq | |
IL_0131: stloc.s 17 | |
IL_0133: ldloc.s 17 | |
IL_0135: brtrue.s IL_013f | |
IL_0137: ldloc.s 20 | |
IL_0139: callvirt instance void [mscorlib]System.IDisposable::Dispose() | |
IL_013e: nop | |
IL_013f: endfinally | |
} // end handler | |
IL_0140: nop | |
IL_0141: ldloc.s 11 | |
IL_0143: callvirt instance int64 WindowsFormsApplication1.HighResolutionTimer::Stop() | |
IL_0148: stloc.s 13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment