Skip to content

Instantly share code, notes, and snippets.

@thenathanjones
Created March 13, 2012 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thenathanjones/2028259 to your computer and use it in GitHub Desktop.
Save thenathanjones/2028259 to your computer and use it in GitHub Desktop.
C# Implementation
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