Are Java static calls more or less expensive than non-static calls?

First: you shouldn’t be making the choice of static vs non-static on the basis of performance. Second: in practice, it won’t make any difference. Hotspot may choose to optimize in ways that make static calls faster for one method, non-static calls faster for another. Third: much of the mythos surrounding static versus non-static are based … Read more

Is C notably faster than C++ [closed]

C++ is often used for scientific programs. The popularity of C may be waning in that domain. Fortran remains popular as a “low-level” language. In C++, “you only pay for what you use.” So there is nothing that would make it any slower than C. In particular for scientific programs, expression templates make it possible … Read more

Is PHP’s count() function O(1) or O(n) for arrays?

Well, we can look at the source: /ext/standard/array.c PHP_FUNCTION(count) calls php_count_recursive(), which in turn calls zend_hash_num_elements() for non-recursive array, which is implemented this way: ZEND_API int zend_hash_num_elements(const HashTable *ht) { IS_CONSISTENT(ht); return ht->nNumOfElements; } So you can see, it’s O(1) for $mode = COUNT_NORMAL.

Why is SSE scalar sqrt(x) slower than rsqrt(x) * x?

sqrtss gives a correctly rounded result. rsqrtss gives an approximation to the reciprocal, accurate to about 11 bits. sqrtss is generating a far more accurate result, for when accuracy is required. rsqrtss exists for the cases when an approximation suffices, but speed is required. If you read Intel’s documentation, you will also find an instruction … Read more

What is the performance of Objects/Arrays in JavaScript? (specifically for Google V8)

I created a test suite, precisely to explore these issues (and more) (archived copy). And in that sense, you can see the performance issues in this 50+ test case tester (it will take a long time). Also as its name suggest, it explores the usage of using the native linked list nature of the DOM … Read more

Best practice for passing many arguments to method?

In Effective Java, Chapter 7 (Methods), Item 40 (Design method signatures carefully), Bloch writes: There are three techniques for shortening overly long parameter lists: break the method into multiple methods, each which require only a subset of the parameters create helper classes to hold group of parameters (typically static member classes) adapt the Builder pattern … Read more

Timertask or Handler

Handler is better than TimerTask. The Java TimerTask and the Android Handler both allow you to schedule delayed and repeated tasks on background threads. However, the literature overwhelmingly recommends using Handler over TimerTask in Android (see here, here, here, here, here, and here). Some of reported problems with TimerTask include: Can’t update the UI thread … Read more