Both tasks can be performed equally quickly in any language. They can also be done terribly wrong and terribly slow in both languages, so this must be taken into account.
In one of your comments, you will note that you are formatting on the server side of SQL. These requests would potentially be a lot cheaper if you did it from the application side and then moved this script to a faster machine in order to least affect the db server.
I would suggest that hard drive speed is your biggest problem. You must control resources while this script is running - is this maximizing your processor? Is reading / writing a lot in memory? (it should not). Is it just waiting on an i / o drive most of the time? If so, you should consider upgrading your storage to faster drives, raids, or ssd, depending on what matters most to your situation.
Even something like disk defragmentation can help.
If you have good cpu / memory, but you can avoid a slow disk, you can even compile all the output in memory before writing (again, assuming this is a good idea, it really depends on where these reports go and which format is needed).
source share