The declarative code is a bit slower. On my system it's about half the speed of the imperative code. The ranges are lazily constructed and very efficient, and only allocate locals on the stack, but it still involves a little more under the hood, like tracking start/end pointers, which adds up in nested loops etc.
Is declarative better than imperative?
Just because one language is declarative or imperative does not mean that it doesn't have certain features of the other. Also, one benefit of declarative programming is that purpose is usually more easily understood from reading the code whereas imperative gives you finer control over execution.
What is declarative programming suitable for?
The declarative style is thus well suited for prototyping in agile software development.