The performance impact of using instanceof in Java

Approach I wrote a benchmark program to evaluate different implementations: instanceof implementation (as reference) object-orientated via an abstract class and @Override a test method using an own type implementation getClass() == _.class implementation I used jmh to run the benchmark with 100 warmup calls, 1000 iterations under measuring, and with 10 forks. So each option … Read more

Frequency counts for unique values in a NumPy array

Use numpy.unique with return_counts=True (for NumPy 1.9+): import numpy as np x = np.array([1,1,1,2,2,2,5,25,1,1]) unique, counts = np.unique(x, return_counts=True) >>> print(np.asarray((unique, counts)).T) [[ 1 5] [ 2 3] [ 5 1] [25 1]] In comparison with scipy.stats.itemfreq: In [4]: x = np.random.random_integers(0,100,1e6) In [5]: %timeit unique, counts = np.unique(x, return_counts=True) 10 loops, best of 3: … Read more

Tracking the script execution time in PHP

If all you need is the wall-clock time, rather than the CPU execution time, then it is simple to calculate: //place this before any script you want to calculate time $time_start = microtime(true); //sample script for($i=0; $i<1000; $i++){ //do anything } $time_end = microtime(true); //dividing with 60 will give the execution time in minutes otherwise … Read more

regex.test V.S. string.match to know if a string matches a regular expression

Basic Usage First, let’s see what each function does: regexObject.test( String ) Executes the search for a match between a regular expression and a specified string. Returns true or false. string.match( RegExp ) Used to retrieve the matches when matching a string against a regular expression. Returns an array with the matches or null if … Read more

Is recursion ever faster than looping?

This depends on the language being used. You wrote ‘language-agnostic’, so I’ll give some examples. In Java, C, and Python, recursion is fairly expensive compared to iteration (in general) because it requires the allocation of a new stack frame. In some C compilers, one can use a compiler flag to eliminate this overhead, which transforms … Read more

What are the performance characteristics of sqlite with very large database files? [closed]

So I did some tests with sqlite for very large files, and came to some conclusions (at least for my specific application). The tests involve a single sqlite file with either a single table, or multiple tables. Each table had about 8 columns, almost all integers, and 4 indices. The idea was to insert enough … Read more

MySQL vs MongoDB 1000 reads

MongoDB is not magically faster. If you store the same data, organised in basically the same fashion, and access it exactly the same way, then you really shouldn’t expect your results to be wildly different. After all, MySQL and MongoDB are both GPL, so if Mongo had some magically better IO code in it, then … Read more