I'm looking to use a method of outputting a 2D array that is optimized for speed. currently I'm using:
for (int row(0); row < 20; ++row)
{
for (int col(0); col < 30; ++col)
{
putchar(grid[row][col]);
}
putchar('\n');
}
this works fine however after testing a few things I noticed that using
printf("%s", grid);
I received a massive speed boost, however this was formatted incorrectly as it just output a long string of chars for my array rather than the 30x20 grid I want. I'm wondering if there is any method to get the speed shown with the printf line that formats the grid correctly.
For reference I get about 33ms when using the first method and 1.5ms with the second method.
printf()in the second code?printfor similar. But your needs looks suspicious to me. Don't try to optimize something that will probably turn out to be useless.