Add performance tests to measure context switching overhead.
Fix bug in work counting introduced by db2bedc862d47da203c98c033f3003e02bf05d5b.
Add an optimisation for single-threaded cases.