473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

JIT compiler global optimization ?


I do a project using C# and C++ .NET and have some functionality to convert
imperial to metric units and vice versa.

In VC6 I just used a simple header file with some constants (e.g. const
double MM_TO_INCH = 1.0/25.4;).

For .NET I thought it might be a good idea to have a class with static
methods for that to use in C# as well as C++ code.
C# didn't work well for that because I could not overload methods if they
only differ in types.
So I did the implementation in a C++ class called Units (e.g. static Double
MMtoINCH (Double MM) { return MM/(Double)25.4; } for the basic float types.

It works, but my concern is about the performance.
With VC6 the compiler would easily replace the function call by inlining the
code.
With .NET I have the IL code in an assembly which needs to be loaded and
then compiled by the JIT.

Does anyone know how good the JIT compiler handles this issue? Is he able to
do the same kind of global optimization? Do I lose performance?

Thanks
Carl

Jul 21 '05 #1
3 2023
"Carl" <Ca**@discussions.microsoft.com> wrote in
news:67**********************************@microsof t.com...

I do a project using C# and C++ .NET and have some functionality to
convert
imperial to metric units and vice versa.

In VC6 I just used a simple header file with some constants (e.g. const
double MM_TO_INCH = 1.0/25.4;).

For .NET I thought it might be a good idea to have a class with static
methods for that to use in C# as well as C++ code.
C# didn't work well for that because I could not overload methods if they
only differ in types.
Do you mean differ in return types?
That applies to C++ as well.
So I did the implementation in a C++ class called Units (e.g. static
Double
MMtoINCH (Double MM) { return MM/(Double)25.4; } for the basic float
types.
Doing e.g. this:
static double MMtoINCH (double MM) { return MM/(double)25.4; }
static float MMtoINCH (float MM) { return MM/(float)25.4; }

In C# works fine.
Post a sample if you need help on that topic.
It works, but my concern is about the performance.
With VC6 the compiler would easily replace the function call by inlining
the
code.
So does the JIT. (in a release build)
With .NET I have the IL code in an assembly which needs to be loaded and
then compiled by the JIT.

Does anyone know how good the JIT compiler handles this issue? Is he able
to
do the same kind of global optimization? Do I lose performance?


Actually, the .NET JIT can inline function calls even across assembly
borders: If your helper functions are in one assembly, the code that uses
them in another one, the JIT will still be able to inline the calls.

Niki
Jul 21 '05 #2

"Niki Estner" wrote:
Do you mean differ in return types?
That applies to C++ as well.
You're right it works or works not in C# and C++ the same way. I missed to
change the parameter type in my C# test class, not just the return type.
Doing e.g. this:
static double MMtoINCH (double MM) { return MM/(double)25.4; }
static float MMtoINCH (float MM) { return MM/(float)25.4; }
That's exactly how I did it in C++. Tried to use a template first, but was
not successful with that.
So does the JIT. (in a release build)
Actually, the .NET JIT can inline function calls even across assembly
borders: If your helper functions are in one assembly, the code that uses
them in another one, the JIT will still be able to inline the calls.


That's great and is exactly what I liked to know.

Thanks a lot
Carl

Jul 21 '05 #3

"Niki Estner" wrote:
Do you mean differ in return types?
That applies to C++ as well.
You're right. It work or works not the same way in C++ and C#. I missed to
change the parameter types in my C# test class (not only the return types).
Doing e.g. this:
static double MMtoINCH (double MM) { return MM/(double)25.4; }
static float MMtoINCH (float MM) { return MM/(float)25.4; }
That's exactly how I did it in C++. Tried to use a template, but was not
successful with that.
So does the JIT. (in a release build)
Actually, the .NET JIT can inline function calls even across assembly
borders: If your helper functions are in one assembly, the code that uses
them in another one, the JIT will still be able to inline the calls.


That's great and exactly what I liked to know.

Thanks a lot
Carl

Jul 21 '05 #4

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

Similar topics

14
by: joshc | last post by:
I'm writing some C to be used in an embedded environment and the code needs to be optimized. I have a question about optimizing compilers in general. I'm using GCC for the workstation and Diab...
5
by: Hari | last post by:
Guys please help me to solve this strange problem what Iam getting as follows.. Trying to instantiate a global instance of a template class as follows :- when i build this code with debug and...
3
by: Carl | last post by:
I do a project using C# and C++ .NET and have some functionality to convert imperial to metric units and vice versa. In VC6 I just used a simple header file with some constants (e.g. const...
44
by: Don Kim | last post by:
Ok, so I posted a rant earlier about the lack of marketing for C++/CLI, and it forked over into another rant about which was the faster compiler. Some said C# was just as fast as C++/CLI, whereas...
5
by: wkaras | last post by:
I've compiled this code: const int x0 = 10; const int x1 = 20; const int x2 = 30; int x = { x2, x0, x1 }; struct Y {
1
by: John Goche | last post by:
/* Consider the following C snippet: */ Foo *pFoo = NULL; void FooLength(Foo *pFoo); void FooHello(Foo **ppFoo); void FooWorld(Foo **ppFoo);
42
by: jacob navia | last post by:
http://slashdot.org/ "The leaner, lighter, faster, and most importantly, BSD Licensed, Compiler PCC has been imported into OpenBSD's CVS and NetBSD's pkgsrc. The compiler is based on the...
5
by: junky_fellow | last post by:
Guys, Please have a look at the following piece of code: int gcount = 0; int gdelay = 0; /* both gcount and gdelay are changed outside this function by an interrupt handler code */
29
by: sammy | last post by:
Word up! If there are any gcc users here, maybe you could help me out. I have a program and I've tried compiling it with -O2 and -O3 optimization settings. The wired thing is that it actually...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.