Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am learning a little more about PHP instead of the basic formatting, etc. One of the questions I have is that with the math part of PHP I can do some rather interesting things with math.

I am also remembering computers understand binary, which is the purest format for all computer languages, but because us as a human species have such a short lifespan we tend to write in everything but binary because to write something in binary would take quite some time, and not worth it.

But that being said, changing a number from something we can understand which would be 124.2 to the binary version which would be 00110001 00110010 00110100 00101110 00110010, would it be more adventageous to do so?

I'm only asking, because if I want code to run faster, since it will be doing averages, etc... I am wondering if translating it to binary before doing the math would make the program faster, or am I thinking too logically, and today's computers don't really care too much about this any more?

share|improve this question

closed as off topic by Indrek, Hennes, Shinrai, soandos, Nifle Oct 25 '12 at 6:49

Questions on Super User are expected to relate to computer software or computer hardware within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
In essence, are you asking if doing binary calculations in PHP would make your scripts run faster than using the decimal system? –  slhck Oct 24 '12 at 19:06
    
Yes, sorry I tend to use a lot of verbiage. –  Matt Ridge Oct 24 '12 at 19:07
    
You'd better ask it in StackOverflow. SuperUser is not created for it. –  SEARAS Oct 24 '12 at 20:50
add comment

1 Answer

up vote 2 down vote accepted

No, not for an interpreted language such as PHP. There is already so much going on and the language itself is doing lots of translating in the background.

The overheads of getting PHP to translate the number into a different format in order to do the math would negate any possible savings anyway.

To be honest, these days, it isn't all that likely anyway that you would either notice or care. If you have decided to use an interpreted language such as PHP, you have already traded efficiency for convenience. You would need to be doing truly immense numbers of calculations to really notice that much difference. If you do see a performance problem, you will need and want to move to a more efficient language.

share|improve this answer
    
Like what kind of language? I figured PHP and XHTML were pretty efficient, unless you are talking about HTML5 that is... –  Matt Ridge Oct 24 '12 at 19:45
    
No, they are not especially efficient. Just good enough for many purposes. One of the C type languages would be better - in fact anything that is compiled rather than interpreted. Assembler is even more efficient if you are a good coder but you really have to know what you are doing and it does take longer to write most things. –  Julian Knight Oct 24 '12 at 19:48
    
To be honest, probably the best thing for you would be to have a go at writing the code and push a realistic set of data through it to see if PHP is good enough. If it is then great, if not at least you have the logic worked out. Another way to improve performance if you need averages of lots of numbers is to use a SQL database engine to store the data and do the math as these tend to be optimised for this kind of problem. –  Julian Knight Oct 24 '12 at 19:50
    
Well I am learning C++ but I am looking for a web interface while on the road and a program for when you are in front of the computer, so for web based languages this is what I am trying to figure out if doing binary instead of what we read would be better or not. –  Matt Ridge Oct 24 '12 at 19:55
    
OK, fair enough - my answer stands though, there really wouldn't be any useful advantage. Keep your PHP/HTML interface, it really is the way to go. Then add in a SQL database to handle the big data and calculations like averages, max, min, etc when you need a performance boost. –  Julian Knight Oct 24 '12 at 19:59
show 1 more comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.