Здравствуйте, _FRED_, Вы писали:
_FR>Запусти не через студию. Перед этим прогони сборку через NGen.
У меня вот такие результаты этих вот тестов:
using System;
using System.Diagnostics;
class PropertyTest
{
public long Field;
public long Property {
get { return Field; }
set { Field = value; }
}
}
static class Program
{
static long TestField(PropertyTest instance, long tests) {
var sum = 0L;
for(var i = 0L; i < tests; i++) {
instance.Field = i;
sum += instance.Field;
}//for
return sum;
}
static long TestProperty(PropertyTest instance, long tests) {
var sum = 0L;
for(var i = 0L; i < tests; i++) {
instance.Property = i;
sum += instance.Property;
}//for
return sum;
}
static void Test(long tests, Func<PropertyTest, long, long> test) {
var instance = new PropertyTest();
var stopwatch = Stopwatch.StartNew();
var sum = test(instance, tests);
stopwatch.Stop();
Console.WriteLine("Ticks: {0}, Sum: {1}", stopwatch.ElapsedTicks, sum);
}
static void Main(string[] args) {
TestField(new PropertyTest(), 10);
TestProperty(new PropertyTest(), 10);
Console.WriteLine("Environment.Version = {0}:", Environment.Version);
long testsCount;
if(args == null || args.Length != 1 || !Int64.TryParse(args[0], out testsCount)) {
testsCount = 10000000L;
}//if
Console.WriteLine("Tests Count: {0}", testsCount);
Console.Write("[TestField]:\t");
Test(testsCount, TestField);
Console.Write("[TestProperty]:\t");
Test(testsCount, TestProperty);
Console.ReadKey(true);
}
}
Environment.Version = 2.0.50727.3082:
Tests Count: 10000000
[TestField]: Ticks: 133183098, Sum: 49999995000000
[TestProperty]: Ticks: 132275034, Sum: 49999995000000
Environment.Version = 4.0.20506.1:
Tests Count: 10000000
[TestField]: Ticks: 131498505, Sum: 49999995000000
[TestProperty]: Ticks: 131230197, Sum: 49999995000000
ИМХО, свойства рулят (ну, скорее всего будут рулить в следующем фреймворке), как это ни удивительно