|
Hi there,
I have a StreamEvent from a StockExchange Data Provider API. The Event is triggered every time a new price occurs for the respective Instrument on the Exchange.
I can fill the Stream with multiple Intruments, lets say 50.000. So the StreamEvent is triggered about mutiple thousand times in one second.
In the Stream, I first check the price difference in percent between the last price and the new one:
private double abw;
void TPBrief_Brief(int SymbolNr, float NewPrice, float Volume, DateTime Time)
{
abw = (((InstrumentObject)os[SymbolNr]).LastPrice - NewPrice) / (((InstrumentObject)os[SymbolNr]).LastPrice/ 100);
if (abw >= 1.5) {
}
As you can see, I hold my Instrument Objects in a Hashtable, key is Symbolnr, value the InstrumentObject. The first line in this event is the one which is triggered that often, so I just want to know how to optimize this line.
As I learned from various articles, Hashtable should be replaced with a Dictionary, this is one thing I will do.
But what about this variation:
void TPBrief_Brief(int SymbolNr, float NewPrice, float Volume, DateTime Time)
{
IntrumentObject io = ((InstrumentObject)os[SymbolNr]);
abw = (io.LastPrice - NewPrice) / (io.LastPrice/ 100);
if (abw >= 1.5) {
}
Could this be faster than the first one? What's about the Calculation of the difference? Can this code fragment be optimized?
Any help would be appreciated!
|
|
|
|
|
As far as calculating the difference is concerned, may I suggest that you google, bing or otherwise search on performance measurement c#, as there are so many hits that it is difficult to recommend just one.
As far as optimizing the code, the only real way to tell is to measure the performance of as many variations as you can think of. I am not able to see anything obvious, although I am pretty sure that others will offer an opinion.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I doubt this calculation is a bottleneck. Have you done any performance profiling? How much throughput are you getting at the moment? How much throughput are you getting with this handling code removed?
Anyway, a bit of maths gives:
abw = NewPrice / io.LastPrice;
if ( abw >= 1.015 || abw <= 0.985 ) {
Also, if the SymbolNr values are sequential ( or at least small ), you could use an array of InstrumentObject with SymbolNr as the index.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Thank you for your input. The Calculation of the Percentage is a good one
I tested now the calculation with this different algos:
private void StreamEventHash(int SymbolNr, float NewPrice, float Volume, DateTime Zeit_kurs)
{
abw = (((OSObject)osHash[SymbolNr]).LastPrice - NewPrice) / (((OSObject)osHash[SymbolNr]).LastPrice / 100);
if (abw >= 5)
{
}
}
private void StreamEventHashNewObject(int SymbolNr, float Kurs, float Volume, DateTime Zeit_kurs)
{
OSObject oo = ((OSObject)osHash[SymbolNr]);
abw = (oo.LastPrice - NewPrice) / (oo.LastPrice / 100);
if (abw >= 5)
{
}
}
private void StreamEventHashNewObjectAs(int SymbolNr, float Kurs, float Volume, DateTime Zeit_kurs)
{
OSObject oo = osHash[SymbolNr] as OSObject;
abw = (oo.LastPrice - NewPrice) / (oo.LastPrice / 100);
if (abw >= 5)
{
}
}
I use the stopwatch class for this. I found out that the first one is the slowest So there is performance optimization possible.
But I can't tell which one of the other 2 algos are faster, because when I change the order the voids are tested, different results occur. It seems that the one which is tested first is always a little bit slower. I am about to figure out how to get reliable results, maybe to run the tests multiple times in random order.
And than I have to find out what your proposed algo
abw = NewPrice / io.LastPrice;
if ( abw >= 1.015 || abw <= 0.985 ) {
will do
modified on Saturday, July 11, 2009 8:31 AM
|
|
|
|
|
I'd try multiplying by 1/100 instead of dividing by 100, the optimizer is not exactly smart but it will always collapse constants such as "1/100" - and seeing as an fdiv is like 15 times (depends on the divisor) as slow as an fmul and not even pipelined, the difference could be huge.
|
|
|
|
|
Thank you very much for your input.
Anyway, I found out that 1,000,000 triggers only take appr. 500 ms. So this can't be my bottleneck
modified on Saturday, July 11, 2009 10:30 AM
|
|
|
|
|
Oh, I don't know that
That's not exactly useful for you to know, but if I hadn't said it you might be waiting for my reply..
I hope someone else here knows more about that kind of thing
|
|
|
|
|
I found out that 1,000,000 triggers only take appr. 500 ms. So this can't be my bottleneck Frown
It seems that the bottleneck is on the DataProvider APIs side. If I put more than 50.000 instruments in the datastream, then somehow sometimes the events aren't triggered anymore. This is my main problem.
BUT: I now that this has somehow also to do with CPU power. This 'disconnects' happen much more often on systems with slower CPU's. So I think there should be a possibility to improve my App - but I don't know where. I already tried to raise the priority of the DataProvider Client Process - no result.
It seemes that somewhere in the system, if the traffic is high enough, there is a traffic jam causing the strange behaviour. Should I change something in the Network Preferences? But what?
|
|
|
|
|
this is my code
i want the start menu to pop up thru like we press the start button
private void page_Load
{
if(condition)
{
//invoke the start key. i want the menu to pop up just as we click the start menu
SendKeys.Send("^{ESC}");
}
}
its not working
This code was posted by me...
|
|
|
|
|
This will not work, since you send this key strokes to your application only, and not on global level.
Have a look at here[^], it is in VB, but i'm sure you will manage to make in in C# in matter of seconds.
|
|
|
|
|
i need code in c# please send a link containing C# code
This code was posted by me...
|
|
|
|
|
how do i import user32.dll in c# in this contest
This code was posted by me...
|
|
|
|
|
Hi
I have problem in picturebox.
i want to load picture run time basis how can i do this???
|
|
|
|
|
|
thanks sir.
now i want to show that pic the value of textbox.text
for example
my pic location is file///e:/pic/1.jpg and user type in textbox "1" then show pic 1.jpg and user type "2" show pic 2.jpg.
how i do this???
|
|
|
|
|
mjawadkhatri wrote: how i do this???
By getting a beginners book on C#, reading through it carefully and attempting all of the examples.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Means u can't help me in this??
|
|
|
|
|
Means it is such a basic function that you should be able to work out how to do it for yourself.
There are plenty of free E-books for beginners on the internet e.g. C# Yellow Book[^].
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
No, it means that you are so far lost if you can't do this based on what you've been told, that there is just no point in talking to you. Not to be rude, but because if you can't work it out based on what you've been told, you're not going to understand anything we say anyhow.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
hi
I have some C# and Windows mobile question:
1. How to get ID & Serial from Windows mobile ?
2. I have 4 Form's in my program, from 1 form I go to
2 form ..... and 4 form. How I can go back to 1 form ?
3. if I send data from 5 terminal's to WebService, and I need
to get answer, Is Webservice know to send back to the
terminal that send him ?
thank's for any help
|
|
|
|
|
Hello everyone...
I am task to make a program in C# which will automatically "SEND" email every 12 midnight without using our own smtp server, instead the said program will use hotmail web server....
I found this outlook connector myt be the answer but i don't know how.... hope anyone can share thier brilliant ideas.
thanks in advance.
xxx
|
|
|
|
|
If you want to use the SMTP server of Hotmail, here[^] is a list that might help you.
|
|
|
|
|
How to use GetTextExtentPoint32() in C#.
Please provide sample code.
|
|
|
|
|
|
so you meant to say that APIs which we use in C++ needs to access via using DLL import.
and in C# there is no other way to use these API directly.
|
|
|
|