Sunday, January 20, 2008

Measure the duration of an event in VC++ 2005

// time.h included
int i = 100000;
clock_t start, finish;
double duration;

printf( "Time to do %ld empty loops is ", i );

start = clock();
while( i-- )
;
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf( "%2.1f seconds\n", duration );

Wednesday, January 9, 2008

Color of Magic :: I'd sue my face for slander

"Oh, and there is one other thing, " the Patrician said, as the wizard groped for the door handles.
"Yes, lord?" he replied, with a sinking heart.
"I'm sure you won't dream of trying to escape from your obligations by fleeing the city. I judge you to be a born city person. But you may be sure that the lords of the other cities will be appraised of these conditions by nightfall."
"I assure you the thought never even crossed my mind, Lord."
"Indeed? Then if I were you I'd sue my face for slander."
Terry Pratchett, The Color of Magic (p.26)

Tuesday, January 8, 2008

Color of Magic :: Time does not, for all practical purposes, exist

"You'd be Twoflower, wouldn't you? Or is that later?"
"Later?" said Twoflower. "Later than what?" He stopped.
"Well", said the voice. "You see, one of the advantages of being dead is that one is released as it were from the bonds of time and therefore I can see everything that has happened or will happen, all at the same time except that of course I now know that Time does not, for all practical purposes, exist."
"That doesn't sound like a disadvantage," said Twoflower.
"You don't think so? Imagine every moment being at one and the same time a distant memory and a nasty surprise and you'll see what I mean. Anyway, I now recall what it was I am about to tell you. Or have I already done so? That's a fine looking dragon, by the way. Or don't I say that yet?"
...
"I think you already told me that," said Twoflower.
Did I? I certainly intended to," said the dead man.
...
"... But I can see I mustn't keep you. I expect you'll be wanting to rescue your friend."
Twoflower gaped. "Hrun?" he said.
"Not him. The skinny wizard. My son Lio!rt is trying to hack him to pieces. I admired the way you rescued him. Will, I mean."
Terry Pratchett, Color of Magic (p.131)