3 ms·
The code isn't very well written either. For example, the various array printing functions (which are at the top of the file, first thing I saw) call putchar/p
by eklitzke 3y ago
The code isn't very well written either.
For example, the various array printing functions (which are at the top of the file, first thing I saw) call putchar/printf in a loop instead of allocating the entire string and printing it with one call. For a HUGE array that doesn't fit in memory this is the right approach, but for the other 99.9% of the time you're printing a smallish value (otherwise you probably wouldn't be printing to stdout in the first place?) this is going to be way slower than allocating the string and printing it once, because it's going to make way more system calls. Also most libc implementations guard stdio access with a mutex, so you're going to have to do a bunch of mutex acquires as well.
Plus why don't these functions take a FILE*? What happens if you want to print to a file or stderr?
- dekhn 3y agoprinting typically goes to buffered streams, and array printing is not a system call. If you want to print to stderr, you write to fd 2.