You can use the microbenchmark package to conduct "sub-millisecond accurate timing of expression evaluation".
In this example we are comparing the speeds of six equivalent data.table expressions for updating elements in a group, based on a certain condition.
More specifically:
A data....