Float vs Double Performance

On x86 processors, at least, float and double will each be converted to a 10-byte real by the FPU for processing. The FPU doesn’t have separate processing units for the different floating-point types it supports. The age-old advice that float is faster than double applied 100 years ago when most CPUs didn’t have built-in FPUs … Read more

What’s the best way (most efficient) to turn all the keys of an object to lower case?

The fastest I come up with is if you create a new object: var key, keys = Object.keys(obj); var n = keys.length; var newobj={} while (n–) { key = keys[n]; newobj[key.toLowerCase()] = obj[key]; } I’m not familiar enough with the current inner working of v8 to give you a definitive answer. A few years ago … Read more

Android RecyclerView Scrolling Performance

I’ve recently faced the same issue, so this is what I’ve done with the latest RecyclerView support library: Replace a complex layout (nested views, RelativeLayout) with the new optimized ConstraintLayout. Activate it in Android Studio: Go to SDK Manager -> SDK Tools tab -> Support Repository -> check ConstraintLayout for Android & Solver for ConstraintLayout. … Read more

What is the best way to profile javascript execution? [closed]

Firebug Firebug provides a highly detailed profiling report. It will tell you how long each method invocation takes in a giant (detailed) table. console.profile(What is the best way to profile javascript execution? [closed]) //also see console.trace() You need to call console.profileEnd () to end your profile block. See the console API here: http://getfirebug.com/wiki/index.php/Console_API Blackbird Blackbird … Read more

How do I insert a linebreak where the cursor is without entering into insert mode in Vim?

For the example you’ve given, you could use rEnter to replace a single character (the space) with Enter. Then, fspace. to move forward to the next space and repeat the last command. Depending on your autoindent settings, the above may or may not indent the return statement properly. If not, then use sEnterTabEsc instead to … Read more

Weird performance increase in simple benchmark

There is a very simple way to always get the “fast” version of your program. Project > Properties > Build tab, untick the “Prefer 32-bit” option, ensure that the Platform target selection is AnyCPU. You really don’t prefer 32-bit, unfortunately is always turned on by default for C# projects. Historically, the Visual Studio toolset worked … Read more

Trying to understand gcc option -fomit-frame-pointer

Most smaller functions don’t need a frame pointer – larger functions MAY need one. It’s really about how well the compiler manages to track how the stack is used, and where things are on the stack (local variables, arguments passed to the current function and arguments being prepared for a function about to be called). … Read more

Is multiplication faster than float division? [duplicate]

Multiplication is faster than division. At university I was taught that division takes six times that of multiplication. The actual timings are architecture dependent but in general multiplication will never be slower or even as slow as division. Always optimize your code towards using multiplication if the rounding errors allow. So in an example this … Read more

Should a developer aim for readability or performance first? [closed]

You missed one. First code for correctness, then for clarity (the two are often connected, of course!). Finally, and only if you have real empirical evidence that you actually need to, you can look at optimizing. Premature optimization really is evil. Optimization almost always costs you time, clarity, maintainability. You’d better be sure you’re buying … Read more

C# vs C – Big performance difference

You must be comparing debug builds. I just compiled your C code, and got Time elapsed: 0.000000 If you don’t enable optimizations, any benchmarking you do is completely worthless. (And if you do enable optimizations, the loop gets optimized away. So your benchmarking code is flawed too. You need to force it to run the … Read more