小编Cha*_*ini的帖子

为什么性能测试显示列表比我的代码中的数组快得多?

LIST FOR      00:00:00.0000980
LIST FOREACH  00:00:00.0000007
ARRAY FOR     00:00:00.0028450
ARRAY FOREACH 00:00:00.0051233
Run Code Online (Sandbox Code Playgroud)

我一直用数组来制作性能较重的东西,但列表似乎要快得多。

using System;
using System.Diagnostics;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        var cron = NCrontab.Advanced.CrontabSchedule.Parse("0 0 1 1 * 2016",
            NCrontab.Advanced.Enumerations.CronStringFormat.WithYears);
        var date = new System.DateTime(year: 2016, month: 1, day: 1,
            hour: 0, minute: 0, second: 0);
        
        int[] testArray = new int[1000000];
        List<int> testList = new List<int>(1000000);
        
        var stopWatch = new Stopwatch();
        stopWatch.Start();
        for (int i = 0; i < testList.Count;i++)
        {
            var …
Run Code Online (Sandbox Code Playgroud)

.net c# arrays performance list

-1
推荐指数
1
解决办法
1573
查看次数

标签 统计

.net ×1

arrays ×1

c# ×1

list ×1

performance ×1