»¶Ó´ó¼Ò³ÖÐø¹Ø×¢ÆÏÌѳǿؼþ¼¼ÊõÍŶӲ©¿Í£¬¸ü¶à¸üºÃµÄÔ´´ÎÄÕ¾¡ÔÚÕâÀï~~
.NET Core£¨¿ª·ÅÔ´´úÂ룬¿çƽ̨£¬x-copy¿É²¿ÊðµÈ£©ÓÐÐí¶àÁîÈËÐ˷ܵķ½Ã棬ÆäÖÐ×îÖµµÃ³ÆÔ޵ľÍÊÇÆäÐÔÄÜÁË¡£
¸ÐлËùÓÐÉçÇø¿ª·¢ÈËÔ±¶Ô.NET Core×ö³öµÄ¹±Ï×£¬ÆäÖеÄÐí¶à¸Ä½øÒ²½«ÔÚ½ÓÏÂÀ´µÄ¼¸¸ö°æ±¾ÖÐÒýÈë.NET Framework¡£
±¾ÎÄÖ÷Òª½éÉÜ.NET CoreÖеÄһЩÐÔÄܸĽø£¬ÌرðÊÇ.NET Core 2.0Öеģ¬Öصã½éÉܸ÷¸öºËÐÄ¿âµÄһЩʾÀý¡£
¼¯ºÏ
¼¯ºÏÊÇÈκÎÓ¦ÓóÌÐòµÄ»ùʯ£¬Í¬Ê±.NET¿âÖÐÒ²ÓдóÁ¿¼¯ºÏ¡£.NET¿âÖеÄһЩ¸Ä½øÊÇΪÁËÏû³ý¿ªÏú£¬ÀýÈç¼ò»¯²Ù×÷ÒÔ±ã¸üºÃµÄʵÏÖÄÚÁª£¬¼õÉÙÖ¸ÁîÊýÁ¿µÈ¡£ÀýÈ磬ÏÂÃæµÄÕâ¸öʹÓÃQ<T>µÄÀý×Ó£º
using System; using System.Diagnostics; using System.Collections.Generic; public class Test { Main() { while (true) { var q = new Queue<int>(); var sw = Stopwatch.StartNew(); for (int i = 0; i < 100_000_000; i++) { q.Enqueue(i); q.Dequeue(); } Console.WriteLine(sw.Elapsed); } } }
PR dotnet/corefx #2515ÒƳýÁËÕâЩ²Ù×÷ÖÐÏà¶Ô¸´ÔÓµÄÄ£ÊýÔËË㣬ÔÚ¸öÈ˼ÆËã»ú£¬ÒÔÉÏ´úÂëÔÚ.NET 4.7ÉϲúÉúÈçÏÂÊä³ö£º
£º£º00£º01.0107745
¶øʹÓÃ.NET Core 2.0Ôò»á²úÉúÈçÏÂÊä³ö£º
£º£º00£º00.5262378
ÓÉÓÚÕâÊǹÒÖÓʱ¼äËù½ÚÊ¡µÄ£¬½ÏСµÄÖµ¼ÆËãµÄ¸ü¿ì£¬ÕâÒ²±íÃ÷ÍÌÍÂÁ¿Ôö¼ÓÁËÔ¼2±¶£¡
ÔÚÆäËûÇé¿öÏ£¬Í¨¹ý¸ü¸Ä²Ù×÷Ëã·¨µÄ¸´ÔÓÐÔ£¬¿ÉÒÔ¸ü¿ìµØ½øÐвÙ×÷¡£±àдÈí¼þʱ£¬×î³õ±àдµÄÒ»¸ö¼òµ¥ÊµÏÖ£¬ËäÈ»ÊÇÕýÈ·µÄ£¬µ«ÊÇÕâÑùʵÏÖÍùÍù²»ÄܱíÏÖ³ö×î¼ÑµÄÐÔÄÜ£¬Ö±µ½Ìض¨µÄ³¡¾°³öÏÖʱ£¬²Å¿¼ÂÇÈçºÎÌá¸ßÐÔÄÜ¡£ÀýÈ磬SortedSet <T>µÄctor×î³õÒÔÏà¶Ô¼òµ¥µÄ·½Ê½±àд£¬ÓÉÓÚʹÓÃO£¨N ^ 2£©Ëã·¨À´´¦ÀíÖظ´ÏÒò´Ë²»Äܺܺõش¦Àí¸´ÔÓÐÔ¡£¸ÃËã·¨ÔÚPRnetnet / corefx££1955ÖеÄ.NET CoreÖеõ½ÐÞ¸´¡£ÒÔϼò¶ÌµÄ³ÌÐò˵Ã÷ÁËÐÞ¸´µÄÇø±ð£º
using System; using System.Diagnostics; using System.Collections.Generic; using System.Linq; public class Test { Main() { var sw = Stopwatch.StartNew(); var ss = new SortedSet<int>(Enumerable.Repeat(42, 400_000)); Console.WriteLine(sw.Elapsed); } }
ÔÚ¸öÈ˵çÄÔµÄ.NET FrameworkÉÏ£¬Õâ¶Î´úÂëÐèÒª´óÔ¼7.7ÃëÖ´ÐÐÍê³É¡£ÔÚ.NET Core 2.0ÉÏ£¬¼õÉÙµ½´óÔ¼0.013s£¨¸Ä½ø¸Ä±äÁËËã·¨µÄ¸´ÔÓÐÔ£¬¼¯ºÏÔ½´ó£¬½ÚÊ¡µÄʱ¼äÔ½¶à£©¡£
»òÕßÔÚSortedSet <T>ÉÏ¿¼ÂÇÕâ¸öÀý×Ó£º
public class Test { static int s_result; Main() { while (true) { var s = new SortedSet<int>(); for (int n = 0; n < 100_000; n++) { s.Add(n); } var sw = Stopwatch.StartNew(); for (int i = 0; i < 10_000_000; i++) { s_result = s.Min; } Console.WriteLine(sw.Elapsed); } } }
.NET 4.7ÖÐMinºÍMaxµÄʵÏֱ鲼SortedSet <T>µÄÕû¸öÊ÷£¬µ«ÊÇÖ»ÐèÒªÕÒµ½×îС»ò×î´óÖµ¼´¿É£¬ÒòΪʵÏÖ¿ÉÒÔÖ»±éÀúÏà¹ØµÄ½Úµã¡£PR dotnet / corefx££11968ÐÞ¸´ÁË.NET CoreʵÏÖ¡£ÔÚ.NET 4.7ÖУ¬´ËʾÀýÉú³ÉÈçϽá¹û£º
£º£º00£º01.1677880
¶øÔÚ.NET Core 2.0ÖУ¬ÎÒÃǵõ½ÈçϽá¹û£º
£º£º00£º00.0860198
ÏÔʾ³öÏ൱´óµÄʱ¼äϽµºÍÍÌÍÂÁ¿µÄÔö¼Ó¡£
¼´Ê¹ÏñList <T>ÕâÑùµÄÖ÷¹¤×÷ºËÐÄÒ²ÓиĽøµÄ¿Õ¼ä¡£¿¼ÂÇÏÂÃæµÄÀý×Ó£º
using System; using System.Diagnostics; using System.Collections.Generic; public class Test { Main() { while (true) { var l = new List<int>(); var sw = Stopwatch.StartNew(); for (int i = 0; i < 100_000_000; i++) { l.Add(i); l.RemoveAt(0); } Console.WriteLine(sw.Elapsed); } } }
ÔÚ.NET 4.7ÖУ¬»áµÃµ½µÄ½á¹ûÈçÏ£º
£º£º00£º00.4515505
ºÍ.NET Core 2.0£¬µÃµ½£º
£º£º00£º00.3164009
¿ÉÒԿ϶¨µÄÊÇ£¬ÔÚ0.3ÃëÄÚ¿ÉÒÔʵÏÖ1ÒÚ´ÎÕâÑùµÄÌí¼Ó²¢´ÓÁбíÖÐɾ³ýµÄ²Ù×÷£¬Õâ±íÃ÷²Ù×÷¿ªÊ¼²¢²»Âý¡£µ«ÊÇ£¬Í¨¹ýÖ´ÐÐÒ»¸öÓ¦ÓóÌÐò£¬Áбíͨ³£»áÌí¼Óµ½ºÜ¶à£¬Í¬Ê±Ò²½ÚÊ¡ÁË×Üʱ¼äÏûºÄ¡£
¡¡