Fastest way to replace NAs in a large data.table

Here’s a solution using data.table’s := operator, building on Andrie and Ramnath’s answers. require(data.table) # v1.6.6 require(gdata) # v2.8.2 set.seed(1) dt1 = create_dt(2e5, 200, 0.1) dim(dt1) [1] 200000 200 # more columns than Ramnath’s answer which had 5 not 200 f_andrie = function(dt) remove_na(dt) f_gdata = function(dt, un = 0) gdata::NAToUnknown(dt, un) f_dowle = function(dt) … Read more

What are the performance implications of using an immediate-mode GUI compared to a retained-mode GUI?

Since there seems to be some interest in this question still (judging by the views), I thought I might as well post an update. I ended up implementing an immediate-mode GUI as my master’s thesis, and have some numbers in on the performance. The gist is: It’s fine – quality of implementation dominates, not systematic … Read more

What are the pros and cons of performing calculations in sql vs. in your application

It depends on a lot of factors – but most crucially: complexity of calculations (prefer doing complex crunching on an app-server, since that scales out; rather than a db server, which scales up) volume of data (if you need to access/aggregate a lot of data, doing it at the db server will save bandwidth, and … Read more

What is the most efficient way of finding all the factors of a number in Python?

from functools import reduce def factors(n): return set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))) This will return all of the factors, very quickly, of a number n. Why square root as the upper limit? sqrt(x) * sqrt(x) = x. So if the two factors are the … Read more

Why is if (variable1 % variable2 == 0) inefficient?

You are measuring the OSR (on-stack replacement) stub. OSR stub is a special version of compiled method intended specifically for transferring execution from interpreted mode to compiled code while the method is running. OSR stubs are not as optimized as regular methods, because they need a frame layout compatible with interpreted frame. I showed this … Read more

Is Java really slow?

Modern Java is one of the fastest languages, even though it is still a memory hog. Java had a reputation for being slow because it used to take a long time for the VM to start up. If you still think Java is slow, see the benchmarks game results. Tightly optimized code written in a … Read more