Hi!
> writing the image to disk wastes 10 seconds by waiting for 0.1s a
> hundred times.
Are you sure?
> The problem is the key_pressed function. It always attempts to read a
> char from the terminal with a timeout of 1 decisecond. It's better to
> poll the terminal without unnecessary waiting.
>
> On my laptop the improvement is very noticeable if I enable compression.
> With compression disabled, the effect is not so obvious, because disk
> throughput is the bottleneck.
> @@ -54,6 +52,14 @@
> static int key_pressed(const char key)
> {
> char c;
> + fd_set fds;
> + struct timeval tv = {0, 0};
> +
> + FD_ZERO(&fds);
> + FD_SET(0, &fds);
> + if (select(1, &fds, NULL, NULL, &tv) <= 0)
> + return 0;
> +
> if (read(0, &c, 1) > 0 && c == key)
> return 1;
That seems unneccessarily complex, just set stdin to nonblocking mode
and read should return immediately, right?
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures)
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Suspend-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/suspend-devel