Tag Archives: c sharp

Looking for advice on performance difference between DotNET C Sharp and Visual C++ handling memory mapped files

Looking for advice on performance difference between DotNET C Sharp and Visual C++ handling memory mapped files

I am looking for a debate on the difference between these two languages. As for Java, I am under the impression it really offers not much advantage as compared to either language unless you want to run under Linux. To do the equivelant of this under Java, use the NIO framework.

Visual C++ examples:

http://quantlabs.net/academy/forum/technical-forum/are-these-the-best-examples-for-c-memory-mapped-files-and-rapid-in-memory-processing/#p527

C# with performance comparison

http://quantlabs.net/academy/forum/technical-forum/are-these-the-best-examples-for-dotnet-c-sharp-memory-mapped-files-and-rapid-in-memory-processing/#p528

From this benchmark link:

http://www.codeproject.com/Articles/212856/Head-to-head-benchmark-Csharp-vs-NET

I conclude that:
1. C++ can still be 2x time faster than in C# in certain critical number crunching scenarios

2. Dump Mono as that is not even to be used. Stick with Windows Server editions for extra horsepower anf many other advantages for server side features

Other highlights:

C++, on the other hand, reveals absolutely no difference between the template <double> version and the original non-template version

The results are clear. First of all, C++ wins in every case. If you use the x86 JIT, 

Anyway, VC++ wins big this time, typically running twice as fast as .NET, if not more (and Mono brings up the rear again, at 8.6 seconds). My experience suggests that array range checks can’t account for such a big difference, but investigation is hindered because I still don’t know how to look at C#’s optimized assembly. Go ahead and laugh at me. Ha!

The first time I ran this “Polynomials” benchmark in C# and C++ (VS 2008, x86), the result was that C++ finished in 0.034 seconds, and C# in 7.085 seconds, making C++ was 208 times faster! Of course, other than the C++ DEBUG hash_map test that took over 10 hours, this was the most extreme result I had ever seen. The C++ result seemed impossible: the outer loop does 10 million iterations and the two inner loops do 100 iterations each, for a total of 2 billion iterations. There was no way so much work could be done in 0.034 seconds on a 2.83 GHz processor. Indeed, looking at the assembly of the outer loop, you can see that the compiler had done something amazing:

Strangely, however, the MS STL’s map<K,V> is actually faster than its hashtable (hash_map or unordered_map), although not as fast as my hash_map. In the .NET world, SortedDictionary is slower than Dictionary as you would expect… but does it have to be this much slower?

C++ wins by a landslide! C++’s map<K,V> is quite fast, while C#’s SortedDictionary<K,V> is quite slow. 

There’s no clear winner for this test. Generally, C# did a better job in the “double” test (even when C++ is allowed to use SSE2), but a worse job in the FPL8 and FPL16 tests. C# is tied with C++ in the float test, until you enable SSE which causes C++ to win

 

Evidently, C++ is faster than C# if you read the whole file as one block. This makes sense, because .NET actually has to do more work in these tests: it is decoding UTF-8 to UTF-16. Standard C++, in contrast, doesn’t support conversion between text encodings, and these tests use “char” strings (not wchar_t), so the only extra work C++ has to do is to convert line endings (\r\n to \n), work which C# does too.

It is therefore peculiar that C# wins the second test, reading line-by-line (ReadLine() in C# vs getline() orfgets() in C++). It occurs to me I could have optimized the FILE* version better; for example, fgets() does not return the string length. So, to eliminate the '\n' at the end of the string (necessary to make the code’s behavior equivalent to the other two versions), I call strlen() to get the string length, then change the last character to ‘\0’. It might have been faster to convert to std::string first (which determines the string length) and then remove the last character.

***If you use P/Invoke a lot, though, it’s important to consider how long it takes to cross the boundary between C# and C++.

Now, these results are not terrible. But non-P/Invoke calls are much faster, as you’ll see below.

 

 

Join my FREE newsletter to learn more which is better 

 

A comment cam in from a newsletter subscriber so thanks to him:

 

I’ve done this in C#.  I did not do it in C++ as for my needs C# performance was more than sufficient for this case.
When used in conjunction with something like .NET’s AutoResetEvent which can be shared across multiple processes it is surprisingly fast.  So if you are using it for something like inter process communication it works quite well!
Now with respect to how it compares to C++, I am not sure but you could probably test this out pretty quickly.  My guess is that the underlying parts which handle this might even be written in C/C++ and .NET is using p/invoke into these OS DLL’s to offer the functionality.  A simple test might be writing in 100 million objects and seeing how each perform.
Keep in mind that you can mix native/managed fairly easily through the use of C++/CLI or P/Invoke.  Both work very well.
I find C++ to require a bit more effort than C# and a lot more than F# so it’s best saved for algorithms that REALLY benefit from it and even than you can offload to the native side where necessary.  You can always use C++/CLI to wrap your native code and hold a pointer to whatever your native class might be.  The only penalty you are faced with in this case is the additional chatter that might be taking place between the native/managed boundary.
One scenario where managed simply might not work is if it critical that the operation you are performing MUST take place within a specific tolerance level as you are vulnerable to garbage collection operations (but even in this case there is room to tune).
Hopefully you find this useful!
NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Looks like DotNET F SHARP can integrate with C Sharp and C++ with HFT in mind

Looks like DotNET  F SHARP can integrate with C Sharp and C++ with HFT in mind

Will F# kill C++? (stupid question really)

http://geekswithblogs.net/MarkPearl/archive/2010/05/05/does-f-kill-c.aspx

Nice! You can integrate F# by calling native C++

http://stackoverflow.com/questions/15180445/any-ideas-how-to-integrate-f-code-with-native-c

You can even use our famouse PInvoke with F#

http://fdatamining.blogspot.ca/2010/04/pinvoke-native-cc-libraries-in-f.html

I like I what I see.. so why use cumbersome library project to integrate Python into .NET? F# is flawless as it is now becoming a core .NET language for the framework. I have seen some neat demos of it integrating with databases as well

Join my FREE newsletter to see if we start using F# 

 

 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Hoorary Matlab charting can keep up with DotNet C Sharp real time tick data from IQFeed

Hoorary Matlab charting can keep up with DotNet C Sharp real time tick data from IQFeed

This is pretty big news as you don’t need an expensive charting packages to keep up with real time IQFeed market tick data!

Join my FREE newsletter to see how we implement this type of charting capabilities 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

How DotNet SQL Server F Sharp and C Sharp and Matlab gaining popularity while R drops

How DotNet SQL Server F Sharp and C Sharp and Matlab gaining popularity while R drops

This video says it all really

Join my FREE newsletter no how we use these languages

 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Overview of Excel with pair trading for trade signals with DotNet C Sharp with Interactive Brokers and MS SQL Server

Overview of Excel with pair trading for trade signals with DotNet C Sharp with Interactive Brokers and MS SQL Server

Woohooo! This is pretty well complete for now depsite the risk management and market position reconciliation pieces.

All source code is available for my Quant Elite members.

Join here

Or join my FREE newsletter to see other trading strategies

 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

My Quant Book review on What are the secrets to profits in HFT with DotNet C Sharp in Financial applications

My Quant Book  review on What are the secrets to profits in HFT with DotNet C Sharp in Financial applications

This is the first video you should watch on the two parts I talk about.

http://www.amazon.com/Financial-Markets-Wiley-Finance-Series/dp/0470030089

Join my FREE newsletter to learn how I will apply these coding techniques to my trading environment

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Quant Book Review on DotNet C Sharp in Financial applications book with fixed income swaptions options derivatives

Quant Book Review on DotNet C Sharp in Financial applications book with fixed income swaptions options derivatives

Very good book introducing these missing and lesser known market assets

http://www.amazon.com/Financial-Markets-Wiley-Finance-Series/dp/0470030089

Join my FREE Learn how I plan to use this book for my trading environment

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Does this article hint DOTNet C Sharp could be as fast as C++ with STL for quant and HFT trading platform development?

Hi there

I was surprised when I say this:

Does this article hint that DOTNet C Sharp could be as fast as C++ with STL for quant and HFT trading platform development? – See more at: https://quantlabs.net/blog/2013/12/does-this-article-hint-that-dotnet-c-sharp-could-be-as-fast-as-c-with-stl-for-quant-and-hft-trading-platform-development/#sthash.WBmhwGda.dpuf

Depending on your libraries, C++ could slow down your development time if you have bloated libraries. C# could make it easier.

Did you you know my current workshop on showing you how to develop an automated trading system in C#? It even comes with source code. Get the entire schedule here.

I have dozens of coding samples in C#, C++, R, Matlab, and even more! Learn how to trade with programming in my QuantLabs.net Premium Membership

GET INSTANT ACCESS HERE

Of course this will not last forever as I am removing all PUBLIC ACCESS after Jan 6 forever,

See  some extra info listed here!

Thanks Bryan

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Improved CSharp DotNet WinForm with live IQFeed market data fed into potential quant trading strategy or model

HI there

Another source sample was just posted:

Improved WinForm with live IQFeed market data fed into potential quant trading strategy or model

https://quantlabs.net/blog/2013/10/improved-winform-with-live-iqfeed-market-data-fed-into-potential-quant-trading-strategy-or-model/

Thanks to the London Quant for doing this. It ensures thread safety in the code to make it more stable. Did I say the source code is included for my QuantLabs.net Premium Members?

So what you waiting for? There will be a lot coding samples like this included. So:

–> JOIN NOW <—


Many benefits listed here.

I hope you have a profitable trading day.

Bryan

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!