Well, the correct answer is to measure it, but you should be able to guess the number of processor steps involved in converting strings and going through them to find the end marker.
Then consider how many FPU / s operations your processor can do and how easy it is to compute a single log.
edit: spend some more time alone in the morning :-)
String s = new Integer(t).toString(); int len = s.length();
One of the problems with high-level languages ββis to guess what kind of work the system does behind the scenes of a clearly simple operator. Mandatory Joel Link
This statement involves allocating memory for the string, and possibly a couple of temporary copies of the string. It should parse the integer and copy its numbers into a string, perhaps reallocate and move the existing memory if the number is large. You may need to check your locale settings to see if your country uses "," or ".". You may have to make a bunch of conversions in Unicode.
Then the length search should check the entire string, again looking at unicode and any local specific settings, such as - are you in the right-left language ?.
Alternatively:
digits = floor( log10( number ) ) + 1;
Just because it will be harder for you to do this on paper does not mean that it is difficult for a computer! In fact, a good rule in high-performance computing, apparently, was - if something is difficult for a person (liquid dynamics, 3D rendering), it is easy for a computer, and if it is easy for a person (face recognition, voice detection in noisy room) it's hard for a computer!
You can usually assume that the built-in math functions are log / sin / cos, etc. have been an important part of computer design for 50 years. Therefore, even if they do not map directly to the hardware function in the FPU, you can bet that an alternative implementation is quite effective.
Martin Beckett Jul 11 2018-11-11T00: 00Z
source share