6 messages in com.mysql.lists.plusplusRe: Result iterator| From | Sent On | Attachments |
|---|---|---|
| Stefan Bicherl | 24 Sep 2001 09:03 | |
| John Hunter | 24 Sep 2001 09:30 | |
| Charles Ouimet | 24 Sep 2001 09:33 | |
| Ryan Gilfether | 24 Sep 2001 11:40 | |
| Carlos Moreno | 24 Sep 2001 13:40 | |
| Darin Buck | 24 Sep 2001 17:43 |
| Subject: | Re: Result iterator![]() |
|---|---|
| From: | John Hunter (jdhu...@ace.bsd.uchicago.edu) |
| Date: | 09/24/2001 09:30:33 AM |
| List: | com.mysql.lists.plusplus |
Some time ago I wrote about an inefficiency in MySQL Row (see the post 'more on Result/Row efficiency; patch included'). It turns out that the Row constructor is very expensive. In the post above, I submitted a patch that sped it up about 30-40% in my test code. (If you don't have access to a list archive, I'll send it your way if you want). I spent a day with a profiler fining out why the result iterator dereferencing is so slow. In that post I go through it in gory detail.
Here are a few things that should speed up your code, some more important than others:
const Result::const_iterator ie( res.end() ); for (i = res.begin(); i != ie; i++) ^ //no need to call end() repeatedly { //row = *i; //you don't need a local copy, a reference will do const Row& thisRow( *i ); if (count % 1000 == 0) { t2 = time(NULL); printf("%d,", t2 - t1); t1 = t2; } count++; }
Also, you should use the prefix rather than the postfix operators (++i and ++count) since the prefix operators don't require a temporary.
None of this explains why your code runs slower and slower as time progresses, but my guess is that if you implement all these changes with the patch, your code may run 2x as fast (mainly the savings will come from the patch and the use of a Row reference).
Let me know what you find out, John Hunter




