Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define WIN32_LEAN_AND_MEAN 1
- #define _CRT_SECURE_NO_WARNINGS 1
- #include <stdio.h>
- #include <stdint.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
- #include <Windows.h>
- #define LIMIT 999999U
- static void test1(void)
- {
- FILE *file = fopen("C:\\Temp\\test1.out", "wb");
- if (!file)
- {
- abort();
- }
- for (size_t i = 0; i < LIMIT; ++i)
- {
- uint8_t buffer = i % 256U;
- if (fwrite(&buffer, sizeof(uint8_t), 1U, file) != 1U)
- {
- abort();
- }
- }
- fclose(file);
- }
- static void test2(void)
- {
- HANDLE h = CreateFileA("C:\\Temp\\test2.out", GENERIC_WRITE, 0U, NULL, CREATE_ALWAYS, 0U, NULL);
- if (h == INVALID_HANDLE_VALUE)
- {
- abort();
- }
- for (size_t i = 0; i < LIMIT; ++i)
- {
- uint8_t buffer = i % 256U;
- DWORD written;
- if (!WriteFile(h, &buffer, 1U, &written, NULL))
- {
- abort();
- }
- if (written != 1U)
- {
- abort();
- }
- }
- CloseHandle(h);
- }
- int main()
- {
- for (int i = 0; i < 3; ++i)
- {
- const clock_t a = clock();
- test1();
- const clock_t b = clock();
- test2();
- const clock_t c = clock();
- printf("stdio: %lu\n", b - a);
- printf("win32: %lu (x%.f)\n", c - b, (c - b) / ((double)(b - a)));
- puts("");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement