C# Mono performanceI was reading through some server logs last week when I detected a performance problem. One database query was taking much more time than expected. The strange thing being I was sure I'd double-checked it in the past. I repeated the test in my laptop and the same performance hit showed up (even clearer taking into account the laptop CPU difference with the server).
Ok, just to give you some numbers:
- The code took about 350ms (.NET 1.1) to execute the query and perform a reader.Read() loop until no more registers were read.
- It included both reading plus processing time: each row had about 15 fields which were read with reader["myfield"] sentences.
- The sample retrieved about 5000 rows.
Well, running exactly the same code using Mono the time reached 1800ms!! A huge performance loss!
Last week we were talking about Mono's string handling performance: while it outperforms .NET in integer based tests, it was clearly behind using strings. So I decided to make a obvious change: what if I accessed the data fields using the integer indexer instead of the string based one? I mean myfield = reader instead of reader["myfield"]??
Well, then Mono took exactly the same time as .NET, which is slightly better than its string based counterpart.
So, until the string based operations get a bit optimized, you can count on the good-ol integer indexer to boost Mono based database access.