相关疑难解决方法(0)

为什么JIT订单会影响性能?

为什么.NET 4.0中的C#方法即时编译的顺序会影响它们执行的速度?例如,考虑两种等效方法:

public static void SingleLineTest()
{
    Stopwatch stopwatch = new Stopwatch();
    stopwatch.Start();
    int count = 0;
    for (uint i = 0; i < 1000000000; ++i) {
        count += i % 16 == 0 ? 1 : 0;
    }
    stopwatch.Stop();
    Console.WriteLine("Single-line test --> Count: {0}, Time: {1}", count, stopwatch.ElapsedMilliseconds);
}

public static void MultiLineTest()
{
    Stopwatch stopwatch = new Stopwatch();
    stopwatch.Start();
    int count = 0;
    for (uint i = 0; i < 1000000000; ++i) {
        var isMultipleOf16 = i % …
Run Code Online (Sandbox Code Playgroud)

.net c# compiler-construction performance jit

34
推荐指数
1
解决办法
1481
查看次数

为什么String.IsNullOrEmpty比String.Length快?

ILSpy表明它String.IsNullOrEmpty是以实现的方式实现的String.Length.但那么为什么String.IsNullOrEmpty(s)速度比s.Length == 0

例如,它在此基准测试中的速度提高了5%:

var stopwatches = Enumerable.Range(0, 4).Select(_ => new Stopwatch()).ToArray();
var strings = "A,B,,C,DE,F,,G,H,,,,I,J,,K,L,MN,OP,Q,R,STU,V,W,X,Y,Z,".Split(',');
var testers = new Func<string, bool>[] { s => s == String.Empty, s => s.Length == 0, s => String.IsNullOrEmpty(s), s => s == "" };
int count = 0;
for (int i = 0; i < 10000; ++i) {
    stopwatches[i % 4].Start();
    for (int j = 0; j < 1000; ++j)
        count += strings.Count(testers[i % …
Run Code Online (Sandbox Code Playgroud)

.net c# string performance is-empty

19
推荐指数
1
解决办法
8315
查看次数

有没有办法改变.NET JIT编译器以支持性能而不是编译时间?

我想知道是否有任何方法可以通过指定更深入优化的首选项来更改.NET JIT编译器的行为.如果不这样做,如果它可以进行某种配置文件引导的优化,如果它还没有,那将是很好的.

.net clr performance jit ngen

14
推荐指数
1
解决办法
1819
查看次数

标签 统计

.net ×3

performance ×3

c# ×2

jit ×2

clr ×1

compiler-construction ×1

is-empty ×1

ngen ×1

string ×1