Since performance of string concatenation is quite weak in VB6 I'm testing several StringBuilder implementations. To see how long they're running, I currently use the built-in
Timer
function which only gives me the number of seconds that have passed after midnight.
Is there a way (I guess by importing a system function) to get something with milliseconds precision?
You can use two Win32 APIs:
These use LARGE_INTEGER to represent 64 bit numbers.
I always use this in a module somewhere (could be in a class though). This code allows you to maintain up to six timers, with high accuracy:
Put the following code in a Stopwatch class:
You can use it as follows:
There's a Thomas Edison story, where he's interviewing some prospective engineers.
He asks them to determine the volume of a light bulb. Candidate A measures it and then uses the formula for the volume of a sphere, and another formula for the volume of the neck, and so on. Candidate B fills it with water and pours it into a measuring cup. Who do you think got the job?
Run it 1000 times and look at your watch before and after. Seconds = milliseconds.
Yes, you can use the Win32 API:
To import it in VB6 declare it like this:
Call it before the operation and after and then calculate the difference in time passed.
There's code and an explanation in the MSDN KB article Q172338 How To Use QueryPerformanceCounter to Time Code