speed optimization

some speed optimization, added example which is useful for profiling purposes