Do you run the query in the GUI or on command-line?
For even better performance, I recommend you to have a look at the following HOF function:
http://docs.basex.org/wiki/Hof_Module#hof:top-k-by
I'm testing the scripts on GUI, I don't really use command line. I also run them on a basexhttp instance. I will check it out, however I like to keep the scripts as close to the xquery spec as possible.