Created
March 13, 2012 11:33
-
-
Save thenathanjones/2028259 to your computer and use it in GitHub Desktop.
C# Implementation
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
public class Class1 | |
{ | |
public static void Main(string[] args) | |
{ | |
var buyTransactions = (new int[200000]).Select(b => new BuyTransaction()); | |
var sellTransactions = (new int[400000]).Select(b => new SellTransaction()); | |
var transactions = buyTransactions.Concat<ITransaction>(sellTransactions); | |
var startTime = DateTime.Now; | |
var total = transactions.Sum(x => x.Amount); | |
var endTime = DateTime.Now; | |
Console.WriteLine(total + " - " + (endTime - startTime).TotalMilliseconds); | |
Console.ReadKey(); | |
} | |
} | |
public class SellTransaction : ITransaction | |
{ | |
public decimal Amount | |
{ | |
get { return Decimal.Parse("5.2342"); } | |
} | |
} | |
public class BuyTransaction : ITransaction | |
{ | |
public decimal Amount | |
{ | |
get { return Decimal.Parse("-10.2342"); } | |
} | |
} | |
public interface ITransaction | |
{ | |
decimal Amount { get; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment