IList<T>
'u uygulayan her şey için bir optimizasyon içerir, bu durumda yalnızca öğeyi -1 uzunluğuna bakar.
tüm kod bakamıyor olanlar için IList<T>
uygulamak ... sen gönderecek şeyler büyük çoğunluğu böyle devam IList<T>
List<int>
int[]
ve uygulayacak unutmayın
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace ConsoleApplication4 {
class Program {
static void Profile(string description, int iterations, Action func) {
// clean up
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
// warm up
func();
var watch = Stopwatch.StartNew();
for (int i = 0; i < iterations; i++) {
func();
}
watch.Stop();
Console.Write(description);
Console.WriteLine(" Time Elapsed {0} ms", watch.ElapsedMilliseconds);
}
static void Main(string[] args) {
int[] nums = Enumerable.Range(1, 1000000).ToArray();
int a;
Profile("Raw performance", 100000,() => { a = nums[nums.Length - 1]; });
Profile("With Last", 100000,() => { a = nums.Last(); });
Console.ReadKey();
}
}
}
Çıktı:
onaylamak, sen gözlem ile onaylayabilirsiniz
Raw performance Time Elapsed 1 ms
With Last Time Elapsed 31 ms
Bu yüzden sadece 30 kat daha yavaştır ve sahip olduğunuz uzunluk listesine sahip performans profilini korur, bu da büyük bir şemada hiçbir şey değildir.
Yineleyiciler için kalıtım ağacı nedir? C++ ilk etapta uzatma metotlarına sahip değildir, bu yüzden '' 'vektöründe '' ('' '' '' '' '' '' '' '' '' '' '' '' '' den farklı bir şekilde uygulanır ve her ikisi için iteratörlerle çalışmak isteyen her şey bir' şablon 'olmalıdır. 'yineleyici 'türü parametresi. –