рдЖрдЬ (
рдЕрдиреБрд╡рд╛рджрдХ рдХрд╛ рдзреНрдпрд╛рди рджреЗрдВ: рдЕрд░реНрдерд╛рдд, 6 рд╕рд╛рд▓ рдкрд╣рд▓реЗ) рдореИрдВ рдлрд╝реЙрд░реЗрд╕реНрдЯ рдирд┐рд░реНрдорд╛рдг рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ рд╕реВрдЪреА рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рдЫрдВрдЯрдиреА рдХрд░ рд░рд╣рд╛ рдерд╛, рдФрд░ рдереЛрдбрд╝рд╛ рд╢рд╛рд▓реАрдирддрд╛ рдорд╣рд╕реВрд╕ рдХрд░ рд░рд╣рд╛ рдерд╛, рдпрд╣ рдорд╣рд╕реВрд╕ рдХрд░рддреЗ рд╣реБрдП рдХрд┐ рдпрд╣ рдХрд┐рддрдирд╛ рдЕрдзрд┐рдХ рдХреБрд╢рд▓ рдерд╛, рдпрд╣ рдХреНрдпрд╛ рд╣реЛрдЧрд╛, ArrayList рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдиреЗ рдХрд╛ рдкреНрд░рдпрд╛рд╕ рдХрд░реЗрдВред рдЬреЗрдиреЗрд░рд┐рдХ рдХреЗ рдЪрдорддреНрдХрд╛рд░ рдХреЗ рд▓рд┐рдП рдзрдиреНрдпрд╡рд╛рдж, рд╕реА # рдХрдВрдкрд╛рдЗрд▓рд░ рдмрдбрд╝реЗ рдкреИрдорд╛рдиреЗ рдкрд░
System.Collections.Generic.IEnumerator System.Collections.IEnumerator . : " ?" , , , , .
NET Framework 2.0 ( . : , ) , , . , , Action, Converter<TInput,TOutput>
Predicate, . , . , . , List.ForEach(Action). , ForEach , Foreach?
:
long Sum(List<int> intList) { long result = 0; foreach (int i in intList) result += i; return result; }
C# IL , :
long Sum(List<int> intList) { long result = 0; List<T>.Enumerator enumerator = intList.GetEnumerator(); try { while (enumerator.MoveNext()) { int i = enumerator.Current; result += i; } } finally { enumerator.Dispose(); } return result; }
, C # : IEnumerator .MoveNext () IEnumerator .Current. List.Enumerator ( IEnumerator) IL callvirt, .
, :
long Sum(List<int> intList) { long result = 0; intList.ForEach(delegate(int i) { result += i; }); result result; } , : long Sum(List<int> intList) { long result = 0; intList.ForEach(i => result += i); return result; }
, List.ForEach , Action<>
, . callvirt IL , , callvirt. , , List.ForEach .
, , List :
for (int i = 0; i < List.Count; i++)
for (int i = 0; i < NUM_ITEMS; i++)
foreach (int i in List)
List.ForEach(delegate(int i) { result += i; });
, :

. , , List.ForEach , ! , ( ) Foreach , . , , , List.ForEach .
, , " ":

, , , , 50% . ForEach- 20%. List.ForEach , , - Foreach- . List.ForEach , Foreach.
, Dell Inspiron 9400 Core Duo T2400 2 . , : ForEachTest.zip (3,82 ).
, , . 5 , 10000000 50000000 .
:

:

: ForEach List, . Array.ForEach
( ) , foreach. , , IEnumerator foreach- . , IL, . , foreach , , Array.ForEach
.
:
.. Unity3D C#, . using UnityEngine; using System.Collections; using System.Collections.Generic; public class testspeed : MonoBehaviour { public enum LoopType {none, for_loop, for_loop_no_count, foreach_loop, ListintForEach} public LoopType type; public int Count=2; public int iterationCount=1000; private List<int> lint = new List<int>(); private int[] alint; private long result; void Start () { for (int i = 0 ; i<Count; i++) {int r=UnityEngine.Random.Range(0,1000); lint.Add(r);} } void Update () { for (int j =0; j<iterationCount;j++) { result=0; switch (type) { case LoopType.for_loop: for (int i = 0; i < lint.Count; i++) {result += lint[i];} break; case LoopType.for_loop_no_count: for (int i = 0; i < Count; i++){result += lint[i];} break; case LoopType.foreach_loop: foreach (int i in lint) {result += i;} break; case LoopType.ListintForEach: lint.ForEach(i => result += i); break; } } } }
, , , 1000 . 1000 , . , , .
:

, . ForEach .
рдЙрджрд╛рд╣рд░рдг рдХреЗ рд╕рд╛рде рдХрдИ рдкреИрдХреЗрдЬрд┐рдВрдЧ рд╕рдВрдЪрд╛рд▓рди рд╕реЗ рдмрдЪрддрд╛ рд╣реИ
System.Collections.Generic.IEnumerator System.Collections.IEnumerator
. : " ?" , , , , .
NET Framework 2.0 ( . : , ) , , . , , Action, Converter<TInput,TOutput>
Predicate, . , . , . , List.ForEach(Action). , ForEach , Foreach?
:
long Sum(List<int> intList) { long result = 0; foreach (int i in intList) result += i; return result; }
C# IL , :
long Sum(List<int> intList) { long result = 0; List<T>.Enumerator enumerator = intList.GetEnumerator(); try { while (enumerator.MoveNext()) { int i = enumerator.Current; result += i; } } finally { enumerator.Dispose(); } return result; }
, C # : IEnumerator .MoveNext () IEnumerator .Current. List.Enumerator ( IEnumerator) IL callvirt, .
, :
long Sum(List<int> intList) { long result = 0; intList.ForEach(delegate(int i) { result += i; }); result result; } , : long Sum(List<int> intList) { long result = 0; intList.ForEach(i => result += i); return result; }
, List.ForEach , Action<>
, . callvirt IL , , callvirt. , , List.ForEach .
, , List :
for (int i = 0; i < List.Count; i++)
for (int i = 0; i < NUM_ITEMS; i++)
foreach (int i in List)
List.ForEach(delegate(int i) { result += i; });
, :

. , , List.ForEach , ! , ( ) Foreach , . , , , List.ForEach .
, , " ":

, , , , 50% . ForEach- 20%. List.ForEach , , - Foreach- . List.ForEach , Foreach.
, Dell Inspiron 9400 Core Duo T2400 2 . , : ForEachTest.zip (3,82 ).
, , . 5 , 10000000 50000000 .
:

:

: ForEach List, . Array.ForEach
( ) , foreach. , , IEnumerator foreach- . , IL, . , foreach , , Array.ForEach
.
:
.. Unity3D C#, . using UnityEngine; using System.Collections; using System.Collections.Generic; public class testspeed : MonoBehaviour { public enum LoopType {none, for_loop, for_loop_no_count, foreach_loop, ListintForEach} public LoopType type; public int Count=2; public int iterationCount=1000; private List<int> lint = new List<int>(); private int[] alint; private long result; void Start () { for (int i = 0 ; i<Count; i++) {int r=UnityEngine.Random.Range(0,1000); lint.Add(r);} } void Update () { for (int j =0; j<iterationCount;j++) { result=0; switch (type) { case LoopType.for_loop: for (int i = 0; i < lint.Count; i++) {result += lint[i];} break; case LoopType.for_loop_no_count: for (int i = 0; i < Count; i++){result += lint[i];} break; case LoopType.foreach_loop: foreach (int i in lint) {result += i;} break; case LoopType.ListintForEach: lint.ForEach(i => result += i); break; } } } }
, , , 1000 . 1000 , . , , .
:

, . ForEach .
System.Collections.Generic.IEnumerator System.Collections.IEnumerator
. : " ?" , , , , .
NET Framework 2.0 ( . : , ) , , . , , Action, Converter<TInput,TOutput>
Predicate, . , . , . , List.ForEach(Action). , ForEach , Foreach?
:
long Sum(List<int> intList) { long result = 0; foreach (int i in intList) result += i; return result; }
C# IL , :
long Sum(List<int> intList) { long result = 0; List<T>.Enumerator enumerator = intList.GetEnumerator(); try { while (enumerator.MoveNext()) { int i = enumerator.Current; result += i; } } finally { enumerator.Dispose(); } return result; }
, C # : IEnumerator .MoveNext () IEnumerator .Current. List.Enumerator ( IEnumerator) IL callvirt, .
, :
long Sum(List<int> intList) { long result = 0; intList.ForEach(delegate(int i) { result += i; }); result result; } , : long Sum(List<int> intList) { long result = 0; intList.ForEach(i => result += i); return result; }
, List.ForEach , Action<>
, . callvirt IL , , callvirt. , , List.ForEach .
, , List :
for (int i = 0; i < List.Count; i++)
for (int i = 0; i < NUM_ITEMS; i++)
foreach (int i in List)
List.ForEach(delegate(int i) { result += i; });
, :

. , , List.ForEach , ! , ( ) Foreach , . , , , List.ForEach .
, , " ":

, , , , 50% . ForEach- 20%. List.ForEach , , - Foreach- . List.ForEach , Foreach.
, Dell Inspiron 9400 Core Duo T2400 2 . , : ForEachTest.zip (3,82 ).
, , . 5 , 10000000 50000000 .
:

:

: ForEach List, . Array.ForEach
( ) , foreach. , , IEnumerator foreach- . , IL, . , foreach , , Array.ForEach
.
:
.. Unity3D C#, . using UnityEngine; using System.Collections; using System.Collections.Generic; public class testspeed : MonoBehaviour { public enum LoopType {none, for_loop, for_loop_no_count, foreach_loop, ListintForEach} public LoopType type; public int Count=2; public int iterationCount=1000; private List<int> lint = new List<int>(); private int[] alint; private long result; void Start () { for (int i = 0 ; i<Count; i++) {int r=UnityEngine.Random.Range(0,1000); lint.Add(r);} } void Update () { for (int j =0; j<iterationCount;j++) { result=0; switch (type) { case LoopType.for_loop: for (int i = 0; i < lint.Count; i++) {result += lint[i];} break; case LoopType.for_loop_no_count: for (int i = 0; i < Count; i++){result += lint[i];} break; case LoopType.foreach_loop: foreach (int i in lint) {result += i;} break; case LoopType.ListintForEach: lint.ForEach(i => result += i); break; } } } }
, , , 1000 . 1000 , . , , .
:

, . ForEach .
System.Collections.Generic.IEnumerator System.Collections.IEnumerator
. : " ?" , , , , .
NET Framework 2.0 ( . : , ) , , . , , Action, Converter<TInput,TOutput>
Predicate, . , . , . , List.ForEach(Action). , ForEach , Foreach?
:
long Sum(List<int> intList) { long result = 0; foreach (int i in intList) result += i; return result; }
C# IL , :
long Sum(List<int> intList) { long result = 0; List<T>.Enumerator enumerator = intList.GetEnumerator(); try { while (enumerator.MoveNext()) { int i = enumerator.Current; result += i; } } finally { enumerator.Dispose(); } return result; }
, C # : IEnumerator .MoveNext () IEnumerator .Current. List.Enumerator ( IEnumerator) IL callvirt, .
, :
long Sum(List<int> intList) { long result = 0; intList.ForEach(delegate(int i) { result += i; }); result result; } , : long Sum(List<int> intList) { long result = 0; intList.ForEach(i => result += i); return result; }
, List.ForEach , Action<>
, . callvirt IL , , callvirt. , , List.ForEach .
, , List :
for (int i = 0; i < List.Count; i++)
for (int i = 0; i < NUM_ITEMS; i++)
foreach (int i in List)
List.ForEach(delegate(int i) { result += i; });
, :
. , , List.ForEach , ! , ( ) Foreach , . , , , List.ForEach .
, , " ":
, , , , 50% . ForEach- 20%. List.ForEach , , - Foreach- . List.ForEach , Foreach.
, Dell Inspiron 9400 Core Duo T2400 2 . , : ForEachTest.zip (3,82 ).
, , . 5 , 10000000 50000000 .
:
:
: ForEach List, . Array.ForEach
( ) , foreach. , , IEnumerator foreach- . , IL, . , foreach , , Array.ForEach
.
:
.. Unity3D C#, . using UnityEngine; using System.Collections; using System.Collections.Generic; public class testspeed : MonoBehaviour { public enum LoopType {none, for_loop, for_loop_no_count, foreach_loop, ListintForEach} public LoopType type; public int Count=2; public int iterationCount=1000; private List<int> lint = new List<int>(); private int[] alint; private long result; void Start () { for (int i = 0 ; i<Count; i++) {int r=UnityEngine.Random.Range(0,1000); lint.Add(r);} } void Update () { for (int j =0; j<iterationCount;j++) { result=0; switch (type) { case LoopType.for_loop: for (int i = 0; i < lint.Count; i++) {result += lint[i];} break; case LoopType.for_loop_no_count: for (int i = 0; i < Count; i++){result += lint[i];} break; case LoopType.foreach_loop: foreach (int i in lint) {result += i;} break; case LoopType.ListintForEach: lint.ForEach(i => result += i); break; } } } }
, , , 1000 . 1000 , . , , .
:
, . ForEach .
System.Collections.Generic.IEnumerator System.Collections.IEnumerator
. : " ?" , , , , .
NET Framework 2.0 ( . : , ) , , . , , Action, Converter<TInput,TOutput>
Predicate, . , . , . , List.ForEach(Action). , ForEach , Foreach?
:
long Sum(List<int> intList) { long result = 0; foreach (int i in intList) result += i; return result; }
C# IL , :
long Sum(List<int> intList) { long result = 0; List<T>.Enumerator enumerator = intList.GetEnumerator(); try { while (enumerator.MoveNext()) { int i = enumerator.Current; result += i; } } finally { enumerator.Dispose(); } return result; }
, C # : IEnumerator .MoveNext () IEnumerator .Current. List.Enumerator ( IEnumerator) IL callvirt, .
, :
long Sum(List<int> intList) { long result = 0; intList.ForEach(delegate(int i) { result += i; }); result result; } , : long Sum(List<int> intList) { long result = 0; intList.ForEach(i => result += i); return result; }
, List.ForEach , Action<>
, . callvirt IL , , callvirt. , , List.ForEach .
, , List :
for (int i = 0; i < List.Count; i++)
for (int i = 0; i < NUM_ITEMS; i++)
foreach (int i in List)
List.ForEach(delegate(int i) { result += i; });
, :

. , , List.ForEach , ! , ( ) Foreach , . , , , List.ForEach .
, , " ":

, , , , 50% . ForEach- 20%. List.ForEach , , - Foreach- . List.ForEach , Foreach.
, Dell Inspiron 9400 Core Duo T2400 2 . , : ForEachTest.zip (3,82 ).
, , . 5 , 10000000 50000000 .
:

:

: ForEach List, . Array.ForEach
( ) , foreach. , , IEnumerator foreach- . , IL, . , foreach , , Array.ForEach
.
:
.. Unity3D C#, . using UnityEngine; using System.Collections; using System.Collections.Generic; public class testspeed : MonoBehaviour { public enum LoopType {none, for_loop, for_loop_no_count, foreach_loop, ListintForEach} public LoopType type; public int Count=2; public int iterationCount=1000; private List<int> lint = new List<int>(); private int[] alint; private long result; void Start () { for (int i = 0 ; i<Count; i++) {int r=UnityEngine.Random.Range(0,1000); lint.Add(r);} } void Update () { for (int j =0; j<iterationCount;j++) { result=0; switch (type) { case LoopType.for_loop: for (int i = 0; i < lint.Count; i++) {result += lint[i];} break; case LoopType.for_loop_no_count: for (int i = 0; i < Count; i++){result += lint[i];} break; case LoopType.foreach_loop: foreach (int i in lint) {result += i;} break; case LoopType.ListintForEach: lint.ForEach(i => result += i); break; } } } }
, , , 1000 . 1000 , . , , .
:

, . ForEach .
System.Collections.Generic.IEnumerator System.Collections.IEnumerator
. : " ?" , , , , .
NET Framework 2.0 ( . : , ) , , . , , Action, Converter<TInput,TOutput>
Predicate, . , . , . , List.ForEach(Action). , ForEach , Foreach?
:
long Sum(List<int> intList) { long result = 0; foreach (int i in intList) result += i; return result; }
C# IL , :
long Sum(List<int> intList) { long result = 0; List<T>.Enumerator enumerator = intList.GetEnumerator(); try { while (enumerator.MoveNext()) { int i = enumerator.Current; result += i; } } finally { enumerator.Dispose(); } return result; }
, C # : IEnumerator .MoveNext () IEnumerator .Current. List.Enumerator ( IEnumerator) IL callvirt, .
, :
long Sum(List<int> intList) { long result = 0; intList.ForEach(delegate(int i) { result += i; }); result result; } , : long Sum(List<int> intList) { long result = 0; intList.ForEach(i => result += i); return result; }
, List.ForEach , Action<>
, . callvirt IL , , callvirt. , , List.ForEach .
, , List :
for (int i = 0; i < List.Count; i++)
for (int i = 0; i < NUM_ITEMS; i++)
foreach (int i in List)
List.ForEach(delegate(int i) { result += i; });
, :
. , , List.ForEach , ! , ( ) Foreach , . , , , List.ForEach .
, , " ":
, , , , 50% . ForEach- 20%. List.ForEach , , - Foreach- . List.ForEach , Foreach.
, Dell Inspiron 9400 Core Duo T2400 2 . , : ForEachTest.zip (3,82 ).
, , . 5 , 10000000 50000000 .
:
:
: ForEach List, . Array.ForEach
( ) , foreach. , , IEnumerator foreach- . , IL, . , foreach , , Array.ForEach
.
:
.. Unity3D C#, . using UnityEngine; using System.Collections; using System.Collections.Generic; public class testspeed : MonoBehaviour { public enum LoopType {none, for_loop, for_loop_no_count, foreach_loop, ListintForEach} public LoopType type; public int Count=2; public int iterationCount=1000; private List<int> lint = new List<int>(); private int[] alint; private long result; void Start () { for (int i = 0 ; i<Count; i++) {int r=UnityEngine.Random.Range(0,1000); lint.Add(r);} } void Update () { for (int j =0; j<iterationCount;j++) { result=0; switch (type) { case LoopType.for_loop: for (int i = 0; i < lint.Count; i++) {result += lint[i];} break; case LoopType.for_loop_no_count: for (int i = 0; i < Count; i++){result += lint[i];} break; case LoopType.foreach_loop: foreach (int i in lint) {result += i;} break; case LoopType.ListintForEach: lint.ForEach(i => result += i); break; } } } }
, , , 1000 . 1000 , . , , .
:
, . ForEach .
System.Collections.Generic.IEnumerator System.Collections.IEnumerator
. : " ?" , , , , .
NET Framework 2.0 ( . : , ) , , . , , Action, Converter<TInput,TOutput>
Predicate, . , . , . , List.ForEach(Action). , ForEach , Foreach?
:
long Sum(List<int> intList) { long result = 0; foreach (int i in intList) result += i; return result; }
C# IL , :
long Sum(List<int> intList) { long result = 0; List<T>.Enumerator enumerator = intList.GetEnumerator(); try { while (enumerator.MoveNext()) { int i = enumerator.Current; result += i; } } finally { enumerator.Dispose(); } return result; }
, C # : IEnumerator .MoveNext () IEnumerator .Current. List.Enumerator ( IEnumerator) IL callvirt, .
, :
long Sum(List<int> intList) { long result = 0; intList.ForEach(delegate(int i) { result += i; }); result result; } , : long Sum(List<int> intList) { long result = 0; intList.ForEach(i => result += i); return result; }
, List.ForEach , Action<>
, . callvirt IL , , callvirt. , , List.ForEach .
, , List :
for (int i = 0; i < List.Count; i++)
for (int i = 0; i < NUM_ITEMS; i++)
foreach (int i in List)
List.ForEach(delegate(int i) { result += i; });
, :

. , , List.ForEach , ! , ( ) Foreach , . , , , List.ForEach .
, , " ":

, , , , 50% . ForEach- 20%. List.ForEach , , - Foreach- . List.ForEach , Foreach.
, Dell Inspiron 9400 Core Duo T2400 2 . , : ForEachTest.zip (3,82 ).
, , . 5 , 10000000 50000000 .
:

:

: ForEach List, . Array.ForEach
( ) , foreach. , , IEnumerator foreach- . , IL, . , foreach , , Array.ForEach
.
:
.. Unity3D C#, . using UnityEngine; using System.Collections; using System.Collections.Generic; public class testspeed : MonoBehaviour { public enum LoopType {none, for_loop, for_loop_no_count, foreach_loop, ListintForEach} public LoopType type; public int Count=2; public int iterationCount=1000; private List<int> lint = new List<int>(); private int[] alint; private long result; void Start () { for (int i = 0 ; i<Count; i++) {int r=UnityEngine.Random.Range(0,1000); lint.Add(r);} } void Update () { for (int j =0; j<iterationCount;j++) { result=0; switch (type) { case LoopType.for_loop: for (int i = 0; i < lint.Count; i++) {result += lint[i];} break; case LoopType.for_loop_no_count: for (int i = 0; i < Count; i++){result += lint[i];} break; case LoopType.foreach_loop: foreach (int i in lint) {result += i;} break; case LoopType.ListintForEach: lint.ForEach(i => result += i); break; } } } }
, , , 1000 . 1000 , . , , .
:

, . ForEach .
System.Collections.Generic.IEnumerator System.Collections.IEnumerator
. : " ?" , , , , .
NET Framework 2.0 ( . : , ) , , . , , Action, Converter<TInput,TOutput>
Predicate, . , . , . , List.ForEach(Action). , ForEach , Foreach?
:
long Sum(List<int> intList) { long result = 0; foreach (int i in intList) result += i; return result; }
C# IL , :
long Sum(List<int> intList) { long result = 0; List<T>.Enumerator enumerator = intList.GetEnumerator(); try { while (enumerator.MoveNext()) { int i = enumerator.Current; result += i; } } finally { enumerator.Dispose(); } return result; }
, C # : IEnumerator .MoveNext () IEnumerator .Current. List.Enumerator ( IEnumerator) IL callvirt, .
, :
long Sum(List<int> intList) { long result = 0; intList.ForEach(delegate(int i) { result += i; }); result result; } , : long Sum(List<int> intList) { long result = 0; intList.ForEach(i => result += i); return result; }
, List.ForEach , Action<>
, . callvirt IL , , callvirt. , , List.ForEach .
, , List :
for (int i = 0; i < List.Count; i++)
for (int i = 0; i < NUM_ITEMS; i++)
foreach (int i in List)
List.ForEach(delegate(int i) { result += i; });
, :
. , , List.ForEach , ! , ( ) Foreach , . , , , List.ForEach .
, , " ":
, , , , 50% . ForEach- 20%. List.ForEach , , - Foreach- . List.ForEach , Foreach.
, Dell Inspiron 9400 Core Duo T2400 2 . , : ForEachTest.zip (3,82 ).
, , . 5 , 10000000 50000000 .
:
:
: ForEach List, . Array.ForEach
( ) , foreach. , , IEnumerator foreach- . , IL, . , foreach , , Array.ForEach
.
:
.. Unity3D C#, . using UnityEngine; using System.Collections; using System.Collections.Generic; public class testspeed : MonoBehaviour { public enum LoopType {none, for_loop, for_loop_no_count, foreach_loop, ListintForEach} public LoopType type; public int Count=2; public int iterationCount=1000; private List<int> lint = new List<int>(); private int[] alint; private long result; void Start () { for (int i = 0 ; i<Count; i++) {int r=UnityEngine.Random.Range(0,1000); lint.Add(r);} } void Update () { for (int j =0; j<iterationCount;j++) { result=0; switch (type) { case LoopType.for_loop: for (int i = 0; i < lint.Count; i++) {result += lint[i];} break; case LoopType.for_loop_no_count: for (int i = 0; i < Count; i++){result += lint[i];} break; case LoopType.foreach_loop: foreach (int i in lint) {result += i;} break; case LoopType.ListintForEach: lint.ForEach(i => result += i); break; } } } }
, , , 1000 . 1000 , . , , .
:
, . ForEach .
System.Collections.Generic.IEnumerator System.Collections.IEnumerator
. : " ?" , , , , .
NET Framework 2.0 ( . : , ) , , . , , Action, Converter<TInput,TOutput>
Predicate, . , . , . , List.ForEach(Action). , ForEach , Foreach?
:
long Sum(List<int> intList) { long result = 0; foreach (int i in intList) result += i; return result; }
C# IL , :
long Sum(List<int> intList) { long result = 0; List<T>.Enumerator enumerator = intList.GetEnumerator(); try { while (enumerator.MoveNext()) { int i = enumerator.Current; result += i; } } finally { enumerator.Dispose(); } return result; }
, C # : IEnumerator .MoveNext () IEnumerator .Current. List.Enumerator ( IEnumerator) IL callvirt, .
, :
long Sum(List<int> intList) { long result = 0; intList.ForEach(delegate(int i) { result += i; }); result result; } , : long Sum(List<int> intList) { long result = 0; intList.ForEach(i => result += i); return result; }
, List.ForEach , Action<>
, . callvirt IL , , callvirt. , , List.ForEach .
, , List :
for (int i = 0; i < List.Count; i++)
for (int i = 0; i < NUM_ITEMS; i++)
foreach (int i in List)
List.ForEach(delegate(int i) { result += i; });
, :

. , , List.ForEach , ! , ( ) Foreach , . , , , List.ForEach .
, , " ":

, , , , 50% . ForEach- 20%. List.ForEach , , - Foreach- . List.ForEach , Foreach.
, Dell Inspiron 9400 Core Duo T2400 2 . , : ForEachTest.zip (3,82 ).
, , . 5 , 10000000 50000000 .
:

:

: ForEach List, . Array.ForEach
( ) , foreach. , , IEnumerator foreach- . , IL, . , foreach , , Array.ForEach
.
:
.. Unity3D C#, . using UnityEngine; using System.Collections; using System.Collections.Generic; public class testspeed : MonoBehaviour { public enum LoopType {none, for_loop, for_loop_no_count, foreach_loop, ListintForEach} public LoopType type; public int Count=2; public int iterationCount=1000; private List<int> lint = new List<int>(); private int[] alint; private long result; void Start () { for (int i = 0 ; i<Count; i++) {int r=UnityEngine.Random.Range(0,1000); lint.Add(r);} } void Update () { for (int j =0; j<iterationCount;j++) { result=0; switch (type) { case LoopType.for_loop: for (int i = 0; i < lint.Count; i++) {result += lint[i];} break; case LoopType.for_loop_no_count: for (int i = 0; i < Count; i++){result += lint[i];} break; case LoopType.foreach_loop: foreach (int i in lint) {result += i;} break; case LoopType.ListintForEach: lint.ForEach(i => result += i); break; } } } }
, , , 1000 . 1000 , . , , .
:

, . ForEach .
System.Collections.Generic.IEnumerator System.Collections.IEnumerator
. : " ?" , , , , .
NET Framework 2.0 ( . : , ) , , . , , Action, Converter<TInput,TOutput>
Predicate, . , . , . , List.ForEach(Action). , ForEach , Foreach?
:
long Sum(List<int> intList) { long result = 0; foreach (int i in intList) result += i; return result; }
C# IL , :
long Sum(List<int> intList) { long result = 0; List<T>.Enumerator enumerator = intList.GetEnumerator(); try { while (enumerator.MoveNext()) { int i = enumerator.Current; result += i; } } finally { enumerator.Dispose(); } return result; }
, C # : IEnumerator .MoveNext () IEnumerator .Current. List.Enumerator ( IEnumerator) IL callvirt, .
, :
long Sum(List<int> intList) { long result = 0; intList.ForEach(delegate(int i) { result += i; }); result result; } , : long Sum(List<int> intList) { long result = 0; intList.ForEach(i => result += i); return result; }
, List.ForEach , Action<>
, . callvirt IL , , callvirt. , , List.ForEach .
, , List :
for (int i = 0; i < List.Count; i++)
for (int i = 0; i < NUM_ITEMS; i++)
foreach (int i in List)
List.ForEach(delegate(int i) { result += i; });
, :

. , , List.ForEach , ! , ( ) Foreach , . , , , List.ForEach .
, , " ":

, , , , 50% . ForEach- 20%. List.ForEach , , - Foreach- . List.ForEach , Foreach.
, Dell Inspiron 9400 Core Duo T2400 2 . , : ForEachTest.zip (3,82 ).
, , . 5 , 10000000 50000000 .
:

:

: ForEach List, . Array.ForEach
( ) , foreach. , , IEnumerator foreach- . , IL, . , foreach , , Array.ForEach
.
:
.. Unity3D C#, . using UnityEngine; using System.Collections; using System.Collections.Generic; public class testspeed : MonoBehaviour { public enum LoopType {none, for_loop, for_loop_no_count, foreach_loop, ListintForEach} public LoopType type; public int Count=2; public int iterationCount=1000; private List<int> lint = new List<int>(); private int[] alint; private long result; void Start () { for (int i = 0 ; i<Count; i++) {int r=UnityEngine.Random.Range(0,1000); lint.Add(r);} } void Update () { for (int j =0; j<iterationCount;j++) { result=0; switch (type) { case LoopType.for_loop: for (int i = 0; i < lint.Count; i++) {result += lint[i];} break; case LoopType.for_loop_no_count: for (int i = 0; i < Count; i++){result += lint[i];} break; case LoopType.foreach_loop: foreach (int i in lint) {result += i;} break; case LoopType.ListintForEach: lint.ForEach(i => result += i); break; } } } }
, , , 1000 . 1000 , . , , .
:

, . ForEach .
System.Collections.Generic.IEnumerator System.Collections.IEnumerator
. : " ?" , , , , .
NET Framework 2.0 ( . : , ) , , . , , Action, Converter<TInput,TOutput>
Predicate, . , . , . , List.ForEach(Action). , ForEach , Foreach?
:
long Sum(List<int> intList) { long result = 0; foreach (int i in intList) result += i; return result; }
C# IL , :
long Sum(List<int> intList) { long result = 0; List<T>.Enumerator enumerator = intList.GetEnumerator(); try { while (enumerator.MoveNext()) { int i = enumerator.Current; result += i; } } finally { enumerator.Dispose(); } return result; }
, C # : IEnumerator .MoveNext () IEnumerator .Current. List.Enumerator ( IEnumerator) IL callvirt, .
, :
long Sum(List<int> intList) { long result = 0; intList.ForEach(delegate(int i) { result += i; }); result result; } , : long Sum(List<int> intList) { long result = 0; intList.ForEach(i => result += i); return result; }
, List.ForEach , Action<>
, . callvirt IL , , callvirt. , , List.ForEach .
, , List :
for (int i = 0; i < List.Count; i++)
for (int i = 0; i < NUM_ITEMS; i++)
foreach (int i in List)
List.ForEach(delegate(int i) { result += i; });
, :

. , , List.ForEach , ! , ( ) Foreach , . , , , List.ForEach .
, , " ":

, , , , 50% . ForEach- 20%. List.ForEach , , - Foreach- . List.ForEach , Foreach.
, Dell Inspiron 9400 Core Duo T2400 2 . , : ForEachTest.zip (3,82 ).
, , . 5 , 10000000 50000000 .
:

:

: ForEach List, . Array.ForEach
( ) , foreach. , , IEnumerator foreach- . , IL, . , foreach , , Array.ForEach
.
:
.. Unity3D C#, . using UnityEngine; using System.Collections; using System.Collections.Generic; public class testspeed : MonoBehaviour { public enum LoopType {none, for_loop, for_loop_no_count, foreach_loop, ListintForEach} public LoopType type; public int Count=2; public int iterationCount=1000; private List<int> lint = new List<int>(); private int[] alint; private long result; void Start () { for (int i = 0 ; i<Count; i++) {int r=UnityEngine.Random.Range(0,1000); lint.Add(r);} } void Update () { for (int j =0; j<iterationCount;j++) { result=0; switch (type) { case LoopType.for_loop: for (int i = 0; i < lint.Count; i++) {result += lint[i];} break; case LoopType.for_loop_no_count: for (int i = 0; i < Count; i++){result += lint[i];} break; case LoopType.foreach_loop: foreach (int i in lint) {result += i;} break; case LoopType.ListintForEach: lint.ForEach(i => result += i); break; } } } }
, , , 1000 . 1000 , . , , .
:

, . ForEach .
System.Collections.Generic.IEnumerator System.Collections.IEnumerator
. : " ?" , , , , .
NET Framework 2.0 ( . : , ) , , . , , Action, Converter<TInput,TOutput>
Predicate, . , . , . , List.ForEach(Action). , ForEach , Foreach?
:
long Sum(List<int> intList) { long result = 0; foreach (int i in intList) result += i; return result; }
C# IL , :
long Sum(List<int> intList) { long result = 0; List<T>.Enumerator enumerator = intList.GetEnumerator(); try { while (enumerator.MoveNext()) { int i = enumerator.Current; result += i; } } finally { enumerator.Dispose(); } return result; }
, C # : IEnumerator .MoveNext () IEnumerator .Current. List.Enumerator ( IEnumerator) IL callvirt, .
, :
long Sum(List<int> intList) { long result = 0; intList.ForEach(delegate(int i) { result += i; }); result result; } , : long Sum(List<int> intList) { long result = 0; intList.ForEach(i => result += i); return result; }
, List.ForEach , Action<>
, . callvirt IL , , callvirt. , , List.ForEach .
, , List :
for (int i = 0; i < List.Count; i++)
for (int i = 0; i < NUM_ITEMS; i++)
foreach (int i in List)
List.ForEach(delegate(int i) { result += i; });
, :
. , , List.ForEach , ! , ( ) Foreach , . , , , List.ForEach .
, , " ":
, , , , 50% . ForEach- 20%. List.ForEach , , - Foreach- . List.ForEach , Foreach.
, Dell Inspiron 9400 Core Duo T2400 2 . , : ForEachTest.zip (3,82 ).
, , . 5 , 10000000 50000000 .
:
:
: ForEach List, . Array.ForEach
( ) , foreach. , , IEnumerator foreach- . , IL, . , foreach , , Array.ForEach
.
:
.. Unity3D C#, . using UnityEngine; using System.Collections; using System.Collections.Generic; public class testspeed : MonoBehaviour { public enum LoopType {none, for_loop, for_loop_no_count, foreach_loop, ListintForEach} public LoopType type; public int Count=2; public int iterationCount=1000; private List<int> lint = new List<int>(); private int[] alint; private long result; void Start () { for (int i = 0 ; i<Count; i++) {int r=UnityEngine.Random.Range(0,1000); lint.Add(r);} } void Update () { for (int j =0; j<iterationCount;j++) { result=0; switch (type) { case LoopType.for_loop: for (int i = 0; i < lint.Count; i++) {result += lint[i];} break; case LoopType.for_loop_no_count: for (int i = 0; i < Count; i++){result += lint[i];} break; case LoopType.foreach_loop: foreach (int i in lint) {result += i;} break; case LoopType.ListintForEach: lint.ForEach(i => result += i); break; } } } }
, , , 1000 . 1000 , . , , .
:
, . ForEach .
System.Collections.Generic.IEnumerator System.Collections.IEnumerator
. : " ?" , , , , .
NET Framework 2.0 ( . : , ) , , . , , Action, Converter<TInput,TOutput>
Predicate, . , . , . , List.ForEach(Action). , ForEach , Foreach?
:
long Sum(List<int> intList) { long result = 0; foreach (int i in intList) result += i; return result; }
C# IL , :
long Sum(List<int> intList) { long result = 0; List<T>.Enumerator enumerator = intList.GetEnumerator(); try { while (enumerator.MoveNext()) { int i = enumerator.Current; result += i; } } finally { enumerator.Dispose(); } return result; }
, C # : IEnumerator .MoveNext () IEnumerator .Current. List.Enumerator ( IEnumerator) IL callvirt, .
, :
long Sum(List<int> intList) { long result = 0; intList.ForEach(delegate(int i) { result += i; }); result result; } , : long Sum(List<int> intList) { long result = 0; intList.ForEach(i => result += i); return result; }
, List.ForEach , Action<>
, . callvirt IL , , callvirt. , , List.ForEach .
, , List :
for (int i = 0; i < List.Count; i++)
for (int i = 0; i < NUM_ITEMS; i++)
foreach (int i in List)
List.ForEach(delegate(int i) { result += i; });
, :

. , , List.ForEach , ! , ( ) Foreach , . , , , List.ForEach .
, , " ":

, , , , 50% . ForEach- 20%. List.ForEach , , - Foreach- . List.ForEach , Foreach.
, Dell Inspiron 9400 Core Duo T2400 2 . , : ForEachTest.zip (3,82 ).
, , . 5 , 10000000 50000000 .
:

:

: ForEach List, . Array.ForEach
( ) , foreach. , , IEnumerator foreach- . , IL, . , foreach , , Array.ForEach
.
:
.. Unity3D C#, . using UnityEngine; using System.Collections; using System.Collections.Generic; public class testspeed : MonoBehaviour { public enum LoopType {none, for_loop, for_loop_no_count, foreach_loop, ListintForEach} public LoopType type; public int Count=2; public int iterationCount=1000; private List<int> lint = new List<int>(); private int[] alint; private long result; void Start () { for (int i = 0 ; i<Count; i++) {int r=UnityEngine.Random.Range(0,1000); lint.Add(r);} } void Update () { for (int j =0; j<iterationCount;j++) { result=0; switch (type) { case LoopType.for_loop: for (int i = 0; i < lint.Count; i++) {result += lint[i];} break; case LoopType.for_loop_no_count: for (int i = 0; i < Count; i++){result += lint[i];} break; case LoopType.foreach_loop: foreach (int i in lint) {result += i;} break; case LoopType.ListintForEach: lint.ForEach(i => result += i); break; } } } }
, , , 1000 . 1000 , . , , .
:

, . ForEach .
System.Collections.Generic.IEnumerator System.Collections.IEnumerator
. : " ?" , , , , .
NET Framework 2.0 ( . : , ) , , . , , Action, Converter<TInput,TOutput>
Predicate, . , . , . , List.ForEach(Action). , ForEach , Foreach?
:
long Sum(List<int> intList) { long result = 0; foreach (int i in intList) result += i; return result; }
C# IL , :
long Sum(List<int> intList) { long result = 0; List<T>.Enumerator enumerator = intList.GetEnumerator(); try { while (enumerator.MoveNext()) { int i = enumerator.Current; result += i; } } finally { enumerator.Dispose(); } return result; }
, C # : IEnumerator .MoveNext () IEnumerator .Current. List.Enumerator ( IEnumerator) IL callvirt, .
, :
long Sum(List<int> intList) { long result = 0; intList.ForEach(delegate(int i) { result += i; }); result result; } , : long Sum(List<int> intList) { long result = 0; intList.ForEach(i => result += i); return result; }
, List.ForEach , Action<>
, . callvirt IL , , callvirt. , , List.ForEach .
, , List :
for (int i = 0; i < List.Count; i++)
for (int i = 0; i < NUM_ITEMS; i++)
foreach (int i in List)
List.ForEach(delegate(int i) { result += i; });
, :

. , , List.ForEach , ! , ( ) Foreach , . , , , List.ForEach .
, , " ":

, , , , 50% . ForEach- 20%. List.ForEach , , - Foreach- . List.ForEach , Foreach.
, Dell Inspiron 9400 Core Duo T2400 2 . , : ForEachTest.zip (3,82 ).
, , . 5 , 10000000 50000000 .
:

:

: ForEach List, . Array.ForEach
( ) , foreach. , , IEnumerator foreach- . , IL, . , foreach , , Array.ForEach
.
:
.. Unity3D C#, . using UnityEngine; using System.Collections; using System.Collections.Generic; public class testspeed : MonoBehaviour { public enum LoopType {none, for_loop, for_loop_no_count, foreach_loop, ListintForEach} public LoopType type; public int Count=2; public int iterationCount=1000; private List<int> lint = new List<int>(); private int[] alint; private long result; void Start () { for (int i = 0 ; i<Count; i++) {int r=UnityEngine.Random.Range(0,1000); lint.Add(r);} } void Update () { for (int j =0; j<iterationCount;j++) { result=0; switch (type) { case LoopType.for_loop: for (int i = 0; i < lint.Count; i++) {result += lint[i];} break; case LoopType.for_loop_no_count: for (int i = 0; i < Count; i++){result += lint[i];} break; case LoopType.foreach_loop: foreach (int i in lint) {result += i;} break; case LoopType.ListintForEach: lint.ForEach(i => result += i); break; } } } }
, , , 1000 . 1000 , . , , .
:

, . ForEach .