1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <fstream>
#include <windows.h>
#include <iostream>
#include <sstream>
#include <iomanip>
DWORD _chrono = 0;
void _start_chrono(void)
{
_chrono = GetTickCount();
}
void _display_chrono(const char * Message)
{
DWORD diff = GetTickCount() - _chrono;
printf("%s : Elapsed time is %.2f s\n", Message, (double)diff / 1000);
}
void _test_write_string_stream(const unsigned long Nb1, const unsigned long Nb2)
{
for(int boucle1 = 0; boucle1 != Nb1; boucle1++)
{
for(int boucle2 = 0; boucle2 != Nb2; boucle2++)
{
std::wstringstream str;
str
<< std::setw(5) << std::setfill(L'0') << boucle1
<< L", "
<< std::setw(5) << std::setfill(L'0') << boucle2
<< L"\n"
;
}
}
}
void _test_write_sprintf(const unsigned long Nb1, const unsigned long Nb2)
{
for(int boucle1 = 0; boucle1 != Nb1; boucle1++)
{
for(int boucle2 = 0; boucle2 != Nb2; boucle2++)
{
wchar_t buffer[1024];
swprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), L"%.5d, %.5d\n", boucle1, boucle2);
}
}
}
int main(int argc, char* argv[])
{
int nb0 = 10;
int nb1 = 1000;
int nb2 = 1000;
for(int boucle = 0; boucle != nb0; boucle++)
{
printf("\n", boucle);
printf("Passe %d\n", boucle);
_start_chrono();
_test_write_sprintf(nb1, nb2);
_display_chrono("write_sprintf");
_start_chrono();
_test_write_string_stream(nb1, nb2);
_display_chrono("write_stringstream");
}
return 0;
} |
Partager