Improved implementation for var and std

This PR uses the techniques that I used for the refactoring of reduction functions to improve the type stability and runtime performance of `var`, and thus `std`.

I just did the benchmarks, the efficiency gap between `Base` and `NumericExtensions` has been virtually closed.