Euphoria To C Translator Optimisations
- Posted by John Cage <drcage2000 at YAHOO.COM> Jan 28, 2001
- 441 views
Hmm... I read the following line: "Imagine the luxury of programming in Euphoria, while producing a .exe file that runs at the speed of compiled C!" again today and figured "Hmm... My Eu programs don't even run at the speed of compiled BASIC...". But why let Rob do all the work optimising the Eu compiler? Lemme pitch in with some clues to what is being done wrong... ------------- Optimisation Tip Nr. 1 ----------------- You often find the following kind of code in your translated sources; RefDS(_20); _1DIGITS = _20; Concat((object_ptr)&_1HEX_DIGITS, _1DIGITS, (s1_ptr)_21); Concat((object_ptr)&_1START_NUMERIC, _1DIGITS, (s1_ptr)_23); RefDS(_39); _1ESCAPE_CHARS = _39; RefDS(_40); _1ESCAPED_CHARS = _40; Now, isn't it possible to rewrite it as this?; RefDS(_20); RefDS(_39); RefDS(_40); _1DIGITS = _20; Concat((object_ptr)&_1HEX_DIGITS, _1DIGITS, (s1_ptr)_21); Concat((object_ptr)&_1START_NUMERIC, _1DIGITS, (s1_ptr)_23); _1ESCAPE_CHARS = _39; _1ESCAPED_CHARS = _40; So that you don't have to call the RefDS() macro everytime inside a heavy loop or something. Call all of them before entering the loop. Allthough I must admit, I haven't looked at what RefDS() actually does... ------------- Optimisation Tip Nr. 2 ----------------- Instead of outputting the following code; _22 = _1wait_key(); if (_22 == 0) goto L0; Output this; if (_1wait_key() == 0) goto L0; A lot smaller, faster, since the compiler can optimise it more easily. ------------- Optimisation Tip Nr. 3 ----------------- Make it so that this: _1 = NewS1(6); Doesn't occur in loops or inside user-defined functions. Call all NewS1()'s at the beginning of main() consecutively. If NewS1() doesn't support this, rewrite it. An alternative would be to implement NewS1() as an '_inline' function, for increased speeds. ------------- Optimisation Tip Nr. 4 ----------------- Change this kind of decrement: _1 = _1string_next - 1; To this: _1 = _1string_next--; Do this for increments aswell. The compiler will compile it into a DEC instruction instead of a SUB. ------------- Optimisation Tip Nr. 5 ----------------- Not an optimisation, but do something about the 20.000 lines .c files that are sometimes produced! My C compiler hangs on them big buffy files! Mike The Spike __________________________________________________ Do You Yahoo!? Yahoo! Auctions - Buy the things you want at great prices. http://auctions.yahoo.com/ ____________________________________________________________ T O P I C A -- Learn More. Surf Less. Newsletters, Tips and Discussions on Topics You Choose. http://www.topica.com/partner/tag01