473,796 Members | 2,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# very optimisation

hi,

do you know where i can find some ebooks or websites talking about C#
optimisation ?

for exemple, i just learned that ++i is faster than i++. i would like to
know more about the things that can make code faster than fast.

thank you.
Nov 17 '05 #1
55 3732
Ennixo <en****@free.fr > wrote:
do you know where i can find some ebooks or websites talking about C#
optimisation ?

for exemple, i just learned that ++i is faster than i++.
In C#? I don't think so. It *can* be faster in *some* languages, but
it's rarely going to make a significant difference.
i would like to
know more about the things that can make code faster than fast.


Proper design and profiling when necessary, basically. Micro-
optimisations rarely make a significant difference to overall
performance - even if tweaking your code makes one section of code five
times faster, unless a significant amount of time is spent in that part
of the code, it's not going to make much difference. Obviously it
depends on the app, but in many apps these days the most significant
performance bottlenecks come from things like network/database access,
bad choice of threading, etc.

Furthermore, micro-optimisations tend to come at the expense of the
code being as readable as it can be, which IMO should be the primary
goal.

If your app isn't performing well enough, get a profiler and find out
exactly where the bottleneck is. At that point, and only at that point,
should you be really worried about micro-optimisations.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
Jon Skeet [C# MVP] a écrit :
Furthermore, micro-optimisations tend to come at the expense of the
code being as readable as it can be, which IMO should be the primary
goal.


generaly yes, but this is for image processing, so i need to optimize as
much as i can, even if the code becomes 10x bigger and unreadable
Nov 17 '05 #3
When talking about image processing, a VERY big performance bonus can be
gained when using unmanaged (unsafe) code and pointers. I remember an
article saying unmanaged image processing can be up to 28 times faster than
managed.
Here it is
http://tinyurl.com/3sux8
"Ennixo" <en****@free.fr > wrote in message
news:42******** *************@n ews.wanadoo.fr. ..
Jon Skeet [C# MVP] a écrit :
> Furthermore, micro-optimisations tend to come at the expense of the
code being as readable as it can be, which IMO should be the primary
goal.


generaly yes, but this is for image processing, so i need to optimize as
much as i can, even if the code becomes 10x bigger and unreadable

Nov 17 '05 #4
Lebesgue a écrit :
When talking about image processing, a VERY big performance bonus can be
gained when using unmanaged (unsafe) code and pointers. I remember an
article saying unmanaged image processing can be up to 28 times faster than
managed.
Here it is
http://tinyurl.com/3sux8


Thank you, i already use unsafe for my processing of course but i would
like to know more about little optimisations now (juste like "++i"
instead of "i++")

but i will read MSDN's unsafe image processing page because i never saw
it before =)
Nov 17 '05 #5
>
Thank you, i already use unsafe for my processing of course but i would
like to know more about little optimisations now (juste like "++i" instead
of "i++")


++i and i++ is not the same if used within things like calling methods and
stuff like that.

Is the one considered faster than the other ?

--
Søren Reinke
www.Xray-Mag.com/ - Your free diving magazin on the net.
Current issue Diving in North America, 99 pages.
Download it in PDF
Nov 17 '05 #6
> for exemple, i just learned that ++i is faster than i++. i would like to
know more about the things that can make code faster than fast.


Where did you read that? There shouldn't be any difference from the
generated code performance.

However, in C# there are similar rules for performance like it is in C++.
The basics in C# are avoiding boxing and use StringBuilder instead of
strings but that shouldn't be useful for image processing anyway.

Nov 17 '05 #7
cody a écrit :
Where did you read that? There shouldn't be any difference from the
generated code performance.


i read it in a source code from csharpfr.com and i saw it in some
sources of codeproject.com
Nov 17 '05 #8
Søren Reinke wrote:
Thank you, i already use unsafe for my processing of course but i would
like to know more about little optimisations now (juste like "++i" instead
of "i++")

Try a profiler, and optimize the places when processing time is actually
used. That way your optimizations may actually matter instead of just
waste your time and make the code unreadable.
++i and i++ is not the same if used within things like calling methods and
stuff like that.
more precicely, ++i and i++ are not the same when used as an expression.
Is the one considered faster than the other ?


When defining your own "operator++ " the x++ variant needs to copy the
old object, ++x does not.

I can't imagine that there is *any* difference whatsoever for the
performance using ++i or i++ (esp. on integral types), and will continue
to think that untill I see a test-program proving otherwise.

--
Helge Jensen
mailto:he****** ****@slog.dk
sip:he********* *@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Nov 17 '05 #9

"Ennixo" <en****@free.fr > wrote in message
news:42******** *************** @news.free.fr.. .
cody a écrit :
Where did you read that? There shouldn't be any difference from the
generated code performance.


i read it in a source code from csharpfr.com and i saw it in some sources
of codeproject.com


I don't think it matter at all.i++ og ++i just add's 1 to the variable.

But if you have some documentation about it i would love to see it.

--
Søren Reinke
www.Xray-Mag.com/ - Your free diving magazin on the net.
Current issue Diving in North America, 99 pages.
Download it in PDF
Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1435
by: OPQ | last post by:
Hi all, I'd happy to have you share some thougts about ultimate optimisations on those 2 topics: (1)- adding one caractere at the end of a string (may be long) (2)- in a dict mapping a key to a list of int, remove every entrie where the list of int have of length < 2
2
1882
by: Simon Elliott | last post by:
What optimisation do compilers typically provide when passing STL containers around? For example, if I do something like this: struct Tbloggs { std::string s1; }; typedef std::vector<Tbloggs> TbloggsList;
16
1494
by: simonwittber | last post by:
Hello People. I've have a very tight inner loop (in a game app, so every millisecond counts) which I have optimised below: def loop(self): self_pool = self.pool self_call_exit_funcs = self.call_exit_funcs self_pool_popleft = self.pool.popleft self_pool_append = self.pool.append
17
2372
by: EC-AKD | last post by:
Hi All, I am new to the concept of optimising codes in C. I was wondering if C level inlining of code is any way comparable to macros. I believe that inlining is equivalent to writing macros. However I had this strange feeling if I should go for macros wherever necessary instead of inlining the codes. In my project, I have to use basic operations like add and sub many times. So I initially inlined them and found a lot of optimisation.
8
1899
by: Jon Maz | last post by:
Hi, I'm facing a code-optimisation issue on an asp.net/vb.net/SQL Server 2000 project. A web page containing not much more than 3 DropDownLists is taking nigh on 6 seconds to load, because each ddl opens up a separate connection to the DB, pulls out its data, and closes its own connection before the next ddl repeats the process. The code to handle each DDL's connection to the DB is packaged in an object (presentation-layer code...
6
3612
by: Lee Harr | last post by:
I have a database where I remove the schema public. When I try to use the createlang script, it fails like this ... >createdb foo CREATE DATABASE >psql foo -c "select version()" version --------------------------------------------------------------------- PostgreSQL 7.4.1 on i386-portbld-freebsd4.9, compiled by GCC 2.95.4 (1 row)
1
2001
by: David Welch | last post by:
Hi, I have a bit of code where I am relying on empty base member optimisation. The bit of code is below: template<typename Enum> struct EncodePrefix { template<Enum e> struct Apply
1
2066
by: grid | last post by:
Hi, I was exploring the affect of cache on program performance/optimisation.Is it the compilers responsibility only to consider this kind of optimisation or the programmer can do his bit in this case ? Reading through the "Expert C Programming" text,it mentions how the below program can be efficient taking the cache details into accont. The below program can be executed using the two versions of copy alternatively and running the time...
2
1259
by: special_dragonfly | last post by:
Hello, I know this might be a little cheeky, and if it is, please say, but I need a little hand optimising some code. For the simple reason that this is 'company' code and I have no idea what I'm allowed to release and not as the case may be I've changed anything that could give an indication of the company - if that makes any sense... for the code below: text_buffer is a single record from an XML stream. I can't read in the entire XML...
0
9528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10012
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7548
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.