Why 2*i is faster than i*2 ?
Announcement
Collapse
No announcement yet.
2*i and i*2
Collapse
X
-
Indeed, a 2*x is translated to a SHL (shift left), while for a x*2 a normal IMUL is used. It's a "parser" thing, IMHO.
Bye!-- The universe tends toward maximum irony. Don't push it.
File Extension Seeker - Metasearch engine for file extensions / file types
Online TrID file identifier | TrIDLib - Identify thousands of file formats
-
I am trying to imagine what made you investigate this phenomenon.
I am stumped, you win.Michael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
What difference does it make as to why? He did and was puzzled by the results.
What I would like to know is how he made the speed comparisons. Just out of idle curiosity, I tried it using TIMER and both came up with zero time. I used the number 5 for the value of I.There are no atheists in a fox hole or the morning of a math test.
If my flag offends you, I'll help you pack.
Comment
-
For code that turn into just a couple of Asm instructions, you need to time adequately: either repeating it lots of times, or checking the RTDSC, etc.
The SHL version turn out about 15% faster, for me (with an Intel Core Duo).
Bye!-- The universe tends toward maximum irony. Don't push it.
File Extension Seeker - Metasearch engine for file extensions / file types
Online TrID file identifier | TrIDLib - Identify thousands of file formats
Comment
-
If you have PB9/5 you can use TIX too. I got speeds about 2x faster for 2*i.
Code:#COMPILE EXE #DIM ALL FUNCTION PBMAIN () AS LONG LOCAL i, ii, ii2 AS LONG LOCAL t1, t2 AS QUAD, sp AS STRING i = 1000000 TIX t1 FOR ii = 1 TO 30000000 'warm up loops ii2 = 2 * i ii2 = i * 2 NEXT TIX END t1 TIX t1 FOR ii = 1 TO 10000000 ii2 = 2 * i NEXT TIX END t1 TIX t2 FOR ii = 1 TO 10000000 ii2 = 2 * i NEXT TIX END t2 sp = "Both 2 * i:" & $CRLF & STR$(t1) & $CRLF & STR$(t2) & $CRLF & "ratio:" & $CRLF & STR$(t2 / t1) TIX t1 FOR ii = 1 TO 10000000 ii2 = i * 2 NEXT TIX END t1 TIX t2 FOR ii = 1 TO 10000000 ii2 = 2 * i NEXT TIX END t2 ? sp & $CRLF & $CRLF & "i * 2 followed by 2 * i:" & $CRLF & STR$(t1) & $CRLF & STR$(t2) & $CRLF & "ratio:" & $CRLF & STR$(t2 / t1) END FUNCTION
Comment
-
>I thought the reason most of us used PB was speed,
I would have guessed the main reason was "ease of use," at least when first getting started.
I'm sure somewhere in PB's marketing department someone has the totals off the bingo cards you get with every new product where you check off the boxes (please check all which apply, thank you!) in the section, "what made you try this product?"
MCMMichael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
'speed'
'ease of use'
'executable size'
'#BLOAT'
'No Vapourware'- Each concept, not only can a solution be found but the user is willing to share how they found it???
- The deeper you learn, the more you find friends that attempted ideas before you , and after you that can either offer help or need help achieving what they may have long since posted
- PB allows us to "Bridge both worlds" with not only code long forgot vs "Hey HERE is the WIZBANG" and show the reason why each work
Personally I think the team at PB has done a PHENOMENAL job at keeping the masses happy, and working on the "Wish-list" and releasing what would best suit the medium, which is why I was drawn to PB and not others given the "New Technology" because the new is REALLY built on the old...but you do not realize it till you get olderEngineer's Motto: If it aint broke take it apart and fix it
"If at 1st you don't succeed... call it version 1.0"
"Half of Programming is coding"....."The other 90% is DEBUGGING"
"Document my code????" .... "WHYYY??? do you think they call it CODE? "
Comment
-
Originally posted by Michael Mattias View PostI am trying to imagine what made you investigate this phenomenon.
I am stumped, you win.
=============================================
To be, or not to be: that is the question:
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune,
Or to take arms against a sea of troubles ...
William Shakespeare (1546-1616)
=============================================It's a pretty day. I hope you enjoy it.
Gösta
My Ego Site: http://www.SwedesDock.comPB Newby Tips: http://www.swedesdock.com/powerbasic/pb_shortcuts.htmlJWAM: (Quit Smoking): http://www.SwedesDock.com/smokingLDN - A Miracle Drug: http://www.SwedesDock.com/LDN/
Comment
-
Gee, haven't you ever been curious? (not to be confused with puzzled)
Of course I must confess to having a longtime deep-seated and unshakeable faith in the absolute veracity of the associative law of multiplication.
MCMMichael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
oh god
Originally posted by Michael Mattias View PostI am trying to imagine what made you investigate this phenomenon.
I am stumped, you win.
I know you are kind of the big Kahuna around here Michael and respect you for your technical knowledge concerning PB, but you really never give it a rest do you? Consider that not all good ideas, questions (or answers) come from you. I wonder why you feel the need to respond to so many others only to criticize or demean.
ok ... before we get into flame wars about who is qualified to say what to who ... I have 3 Engineering degrees too ... you don't see me giving out crap like candy on this site.
Now ... I brace and wait for the much expected witty repartee.
Comment
-
Originally posted by Rodney Hicks View Post'speed'
'ease of use'
'executable size'
'#BLOAT'
'No Vapourware'
These are a few of our favourite things!
"Does it work"?
If it doesn't work, all other considerations are moot. Get it working first then tweek it later.There are no atheists in a fox hole or the morning of a math test.
If my flag offends you, I'll help you pack.
Comment
-
What surprised me was how totally out of left field this was.
It's like waking up and saying, "today I am going to look for Tupperware on my roof" .. that is, it would never occur to me to look for a performance difference between I*2 and 2*I.
I was - and remain - curious as to what inspired this effort.Michael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
Originally posted by Michael Mattias View PostI was - and remain - curious as to what inspired this effort.
=================================
"Research is what I'm doing when
I don't know what I'm doing."
Wernher Von Braun (1912-1977)
=================================It's a pretty day. I hope you enjoy it.
Gösta
My Ego Site: http://www.SwedesDock.comPB Newby Tips: http://www.swedesdock.com/powerbasic/pb_shortcuts.htmlJWAM: (Quit Smoking): http://www.SwedesDock.com/smokingLDN - A Miracle Drug: http://www.SwedesDock.com/LDN/
Comment
-
I have to agree with Mr. Mattias here; that is an unlikely thing to have looked into. My take on his comment was that he was pleasantly surprised at this find, as was I.
It seems as though everyone is so accustomed to MM's chagrin that when it wasn't there, for a change, you imagined that it was.
Barry
Comment
-
If PB had just done "multiply" when it sees "*" all this would be moot, you know.
That is, perhaps it should have been a user responsibilty to optimize multiplication and division by integral powers of two using the SHIFT statement provided.Michael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
Originally posted by Michael Mattias View PostIf PB had just done "multiply" when it sees "*" all this would be moot, you know.
That is, perhaps it should have been a user responsibilty to optimize multiplication and division by integral powers of two using the SHIFT statement provided.
Barry
Comment
Comment