Last active
August 29, 2015 14:19
-
-
Save main--/c8aeafe30170e28d5ec1 to your computer and use it in GitHub Desktop.
ArrayList vs LinkedList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Threading; | |
namespace katzenjammer | |
{ | |
class MainClass | |
{ | |
public static void Main(string[] args) | |
{ | |
var swag = new List<int>(); | |
var noswag = new LinkedList<int>(); | |
var watch = new Stopwatch(); | |
int sz = 10000000; | |
watch.Start(); | |
for (int i = 0; i < sz; i++) | |
swag.Add(i); | |
watch.Stop(); | |
var swagInsert = watch.Elapsed; | |
watch.Reset(); | |
watch.Start(); | |
for (int i = 0; i < sz; i++) | |
noswag.AddLast(i); | |
watch.Stop(); | |
var noswagInsert = watch.Elapsed; | |
watch.Reset(); | |
watch.Start(); | |
int swagSum = 0; | |
foreach (var x in swag) | |
swagSum += x; | |
watch.Stop(); | |
var swagIter = watch.Elapsed; | |
watch.Reset(); | |
watch.Start(); | |
int noswagSum = 0; | |
foreach (var x in noswag) | |
noswagSum += x; | |
watch.Stop(); | |
var noswagIter = watch.Elapsed; | |
Console.WriteLine("swagSum={0} noswagSum={1}", swagSum, noswagSum); | |
Console.WriteLine(); | |
Console.WriteLine("swag vs noswag"); | |
Console.WriteLine("=============="); | |
Console.WriteLine("Insert: {0} vs {1}", swagInsert, noswagInsert); | |
Console.WriteLine("Iterate: {0} vs {1}", swagIter, noswagIter); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment