Code optimisation 
Author Message
 Code optimisation

Hi All,
I was just wondering if anyone could tell me whether or not the C# compiler
contains an optimiser?
I want to create a number of modules in C#, the way I have always done it
(in the past) using C is to leave the test stubs in so they can be re-used
later if required. The optimiser would then remove this redundant code when
not in use.
Can I do the same in C#?

Thanks in advance,
Martin.



Thu, 16 Dec 2004 02:54:36 GMT  
 Code optimisation


Quote:
> Hi All,
> I was just wondering if anyone could tell me whether or not the C#
compiler
> contains an optimiser?
> I want to create a number of modules in C#, the way I have always done it
> (in the past) using C is to leave the test stubs in so they can be re-used
> later if required. The optimiser would then remove this redundant code
when
> not in use.
> Can I do the same in C#?

The C# contains some optimization, but I'm not sure exactly what it does.

What you're looking to do involves compiler directives.

Generally, people have two types of compiles: DEBUG and RELEASE.

What you'd do is put a compiler conditional around your test stubs
so that when the DEBUG compiler directive is set, it WILL compile
the stubs, but when it's set to RELEASE, it WON'T compile.

#if DEBUG

/* Do test stub stuf here */
#endif

See the .NET Framework SDK on "#if preprocessor directive".

Also, I'd like to point out that, generally, it's bad practice
to modify classes for special testing functions. What you
should do is leave the class whole and in-tact, and then
write seperate test classes that test the public or
internal members of the class.

-c



Wed, 15 Dec 2004 23:25:25 GMT  
 Code optimisation
IMO it's better to organize a separate test solution T for any given solution
A.  Include all projects from A in T that are required for testing, and then
write a test harness to exercise everything.

You might also want to take a close look at NUnit, which I am finding a very
useful aid for this kind of systematic testing:

http://nunit.sourceforge.net/

--Bob Grommes


Quote:
> Hi All,
> I was just wondering if anyone could tell me whether or not the C# compiler
> contains an optimiser?
> I want to create a number of modules in C#, the way I have always done it
> (in the past) using C is to leave the test stubs in so they can be re-used
> later if required. The optimiser would then remove this redundant code when
> not in use.
> Can I do the same in C#?

> Thanks in advance,
> Martin.



Thu, 16 Dec 2004 01:56:27 GMT  
 Code optimisation
Thanks Bob,
I'll have a look at NUnit and see if it can do the job.
From what I have been able to see from the books I currently have available,
most if not all of the optimisation is being performed at the JIT compiler
stage.

Martin.


Quote:
> IMO it's better to organize a separate test solution T for any given
solution
> A.  Include all projects from A in T that are required for testing, and
then
> write a test harness to exercise everything.

> You might also want to take a close look at NUnit, which I am finding a
very
> useful aid for this kind of systematic testing:

> http://nunit.sourceforge.net/

> --Bob Grommes



> > Hi All,
> > I was just wondering if anyone could tell me whether or not the C#
compiler
> > contains an optimiser?
> > I want to create a number of modules in C#, the way I have always done
it
> > (in the past) using C is to leave the test stubs in so they can be
re-used
> > later if required. The optimiser would then remove this redundant code
when
> > not in use.
> > Can I do the same in C#?

> > Thanks in advance,
> > Martin.



Thu, 16 Dec 2004 21:10:20 GMT  
 Code optimisation
Martin,

Quote:
> I was just wondering if anyone could tell me whether or not the C#
compiler
> contains an optimiser?
> I want to create a number of modules in C#, the way I have always done it
> (in the past) using C is to leave the test stubs in so they can be re-used
> later if required. The optimiser would then remove this redundant code
when
> not in use.
> Can I do the same in C#?

The C# compiler will not remove unused code. However, that doesn't need to
be necessarily bad. Although the actual MSIL and metadata will still be
there in the resulting assembly, if, at runtime, the code is never used, it
will never be JITed, since the JIT compiler works on a method-by-method
basis.

--
Tomas Restrepo



Fri, 17 Dec 2004 07:08:53 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. OT: Code Optimisation Links

2. Code optimisation concerning pointers

3. code optimisation

4. Code optimisation

5. optimisation de code

6. Q: optimisation of code

7. ENORMOUS Pb with VC7 linker optimisation !

8. Binary tree optimisation

9. Optimisation In C and Algorithm Develpment

10. Algorithm Optimisation Thoughts - Languageh Independent Stage Of Development

11. Sequence Points, Aliasing & Optimisation

12. optimisation

 

 
Powered by phpBB® Forum Software