views:

95

answers:

1

Which one would be more efficient, and why? I'm just getting started with RX and trying to understand how to write better code.

For example I could do

tradesfeed.Where(trade=>trade.Size > 500).Subscribe(x =>
{
    Console.WriteLine("big trade: " + x.Symbol + " " + x.Size);
});

tradesfeed.Where(trade=>trade.Size <= 500).Subscribe(x =>
{
    Console.WriteLine("little trade: " + x.Symbol + " " + x.Size);
});

or have only one subscription

tradesfeed.Subscribe(x =>
{
    if (x.Size > 500)
        Console.WriteLine("big trade: " + x.Symbol + " " + x.Size);
    else
        Console.WriteLine("little trade: " + x.Symbol + " " + x.Size);
});
+2  A: 

The second is more efficient in terms of fewer delegate allocations. But the difference would be so minute, it should not at all be considered a factor in your choice. Go with whatever is simpler for your code and don't worry about micro-optimizations.

Judah Himango