port PR rails/rails#7416

This is a port of https://github.com/rails/rails/pull/7416. I modified the original implementation because there were two problems:

1. `perftest benchmarker` did not work
1. `rake test:profile` did not work

I solved 1.) by setting the environment variable for the benchmarker command. 2.) was related to the definitions of the rake tasks. They are always executed not only when triggered. This meant that the environment variable was always set. I created a setup task, which is a precondition of `rake test:benchmark` to work around this issue.