Prev: Best way to learn ... need some help
Next: A tool that suggests optimized logic for a piece of code/module/function
From: Jasen Betts on 12 Jan 2010 17:53 On 2010-01-11, karthikbalaguru <karthikbalaguru79(a)gmail.com> wrote: > Hi, > There are certain editors that highlight > the syntax/color for datatypes/variables > or comments etc. > > Similarly, > Is there a tool for C language that > could suggest an optimized/alternate > programming logic for the function that > is written ? > > The optimized/alternate logic can be > suggested as soon as we finish coding > for one function or it can be suggested > as soon as the code is compiled/parsed > by that tool. > > It will be even more helpful if that tool > also provides the cycle counts, cache > usage, cache misses and lines of code > also. > > It would be better if that tool has an > option to enable / disable this feature > either through compile time or some > other configurations. > > Any ideas ? you seem to be asking for a compiler that is tightly bopund to an editor, (which seems contrary to the unix philosophy) such compiler is likely to optimise worse than GCC. Tweaked C code is likely to only work well on a single architecture. optimising compilers often alter the order in which statements are executed etc... If you really want to optimise for a single architecture you should probably be coding in assembler anyway. > Thx in advans, > Karthik Balaguru --- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
From: Ed Prochak on 12 Jan 2010 23:58 On Jan 12, 3:19 pm, karthikbalaguru <karthikbalagur...(a)gmail.com> wrote: > On Jan 13, 12:05 am, Andy <jonesa...(a)comcast.net> wrote: > > > On Jan 12, 11:12 am, scattered <still.scatte...(a)gmail.com> wrote: > > > > I don't see why it would be impossible. Optimizing compilers exist and > > > by using similar techniques it should be possible to write a compiler > > > that uses C as both the source and target language. How useful this > > > would be is another question. The resulting code would need to be > > > humanly readable if the tool would be of any use and the would > > > probably place severe restrictions on the sorts of optimizations that > > > can be done. I would be surprised if no work along these lines has > > > been done. > > > The optimizations would have to be limited to that subset that can be > > implemented at the C level. > > True ! > > > That might be difficult to do, since the > > optimization is not usually concerned with whether or not the > > optimized version can be portrayed in C. > > True, but i am looking only at the > C level optimization. > > > The generated C code would have to look similar (same variable names, > > etc.) to the original to be useful. > > I think, in such scenarios, the tool should > be having tremendous knowledge about > the software/program and take care > end to end. Maybe, the tool can generate > report on the changes and the reason for > the changes so the developer can use > it for further developments or any other > maintenance activities on that code. > > > And if the compiler can show you those optimizations in the form of > > modified code, why not have it skip showing you the code and just > > optimize it behind the scenes like it always does? > > Maybe, it would be better if it > can do it before user rather than > behind the scenes so that the user > is aware of the kind of optimzations > that are being done and could be > taken care. It is also needed so that > the developer will be able to take care > of further developments on the same > program/software and also for the > maintenance activities on that > program/software. > > Thx in advans, > Karthik Balaguru There is such a tool. It is called a code review.
From: Chris McDonald on 13 Jan 2010 00:45 Paul Keinanen <keinanen(a)sci.fi> writes: >If the problem on average is badly trained programmers, the obvious >solution should be improving the training of programmers. >A tool that points out suboptimal constructs etc. might be useful in >the training phase, but what is the point of using it in actual >program production ? If sufficiently sophisticated it could be used as a regression tester for code submitted to a revision system. This presumes, however, that it's better to have "optimal" source code than to have readble/expressive source code. -- Chris.
From: Lorenzo Villari on 13 Jan 2010 09:23 On Tue, 12 Jan 2010 23:44:08 +0100 David Brown <david.brown(a)hesbynett.removethisbit.no> wrote: > > Thirdly, rather than having a compiler try to guess what algorithm > you are trying to implement, it would be better to have more > algorithms implemented in the libraries and preferably the language > itself in a way that is natural for the programmer. For example, if > the language has support for real arrays with functions such as > sorting, the programmer can work with an array and let the compiler > figure out the best way to implement it. > 1) Coding a custom algorithm is not natural to the programmer? 2) What's a "real" array? > With C, the programmer will > either write their own bubble sort, or call qsort - with all its > overheads. Which overhead? > This is why programs written in interpreted languages > such as Python can often be faster than compiled C code for code > working with complex data structures, hash tables, sorting, list > manipulation, etc., Of course the C code /could/ be faster - but > people don't write optimal algorithms in most code. With the > libraries and language support in Python, you get very good > algorithms for free. > If you can stand the formatting of python... ouch! It's the same case of custom code vs standard code, or custom C container vs STL C++ container. One asks himself\herself why the c++ people agreed to have a standard way of doing this and the C counterpart won't never agree...
From: Walter Banks on 13 Jan 2010 10:48
Lorenzo Villari wrote: > One asks himself\herself why the c++ people agreed to have a > standard way of doing this and the C counterpart won't never agree... The C vs C++ mindsets are implementation vs application focus. C is used in embedded systems instead of C++ because the embedded systems developer sees their task as creating an effective solution to their perception of a unique application. Regards, -- Walter Banks Byte Craft Limited http://www.bytecraft.com |