optimization
Why does the Java API use int instead of short or byte?
Some of the reasons have already been pointed out. For example, the fact that “…(Almost) All operations on byte, short will promote these primitives to int”. However, the obvious next question would be: WHY are these types promoted to int? So to go one level deeper: The answer may simply be related to the Java … Read more
Is the inequality operator faster than the equality operator?
Usually, the microprocessor does comparison using electrical gates and not step by step like that. It checks all bits at once.
Can compiler optimization introduce bugs?
Compiler optimizations can introduce bugs or undesirable behaviour. That’s why you can turn them off. One example: a compiler can optimize the read/write access to a memory location, doing things like eliminating duplicate reads or duplicate writes, or re-ordering certain operations. If the memory location in question is only used by a single thread and … Read more
Deflate compression browser compatibility and advantages over GZIP
UPDATE: Browsers have been dropping support for raw deflate. zOompf has completed some very thorough research on this very topic here. Unfortunately, it appears that raw deflate is NOT safe to use. Check http://www.vervestudios.co/projects/compression-tests/results for more results. Here are the browsers that have been tested: /* Browser DEFLATE ZLIB */ XP Internet Explorer 6 PASS … Read more
Time complexity of memory allocation
One of the things you have to realise when dealing with O notation is that it is often very important to understand what n is. If the n is something related to something you can control (eg: the number of elements in a list you want sorted) then it makes sense to look hard at … Read more
How can I rank observations in-group faster?
The answer from Marek in this question has proven very useful in the past. I wrote it down and use it almost daily since it was fast and efficient. We’ll use ave() and seq_along(). foo <-data.frame(person=c(rep(“pers1”,3),rep(“pers2”,2)),year=c(1999,2000,2003,1998,2011)) foo <- transform(foo, obs = ave(rep(NA, nrow(foo)), person, FUN = seq_along)) foo person year obs 1 pers1 1999 1 … Read more
What is copy-on-write?
I was going to write up my own explanation but this Wikipedia article pretty much sums it up. Here is the basic concept: Copy-on-write (sometimes referred to as “COW”) is an optimization strategy used in computer programming. The fundamental idea is that if multiple callers ask for resources which are initially indistinguishable, you can give … Read more