#define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
# include <assert.h>
# include <time.h>
# include <stdlib.h>
# include <string.h>
int filefunction(int n)
{
int* res = (int*)calloc(n,sizeof(int));
assert(res != NULL);
for (int i = 0; i < n; i++)
{
res[i] = i;
}
clock_t c1 = clock();
FILE* fw = fopen("D:\\1.txt", "w");
assert(fw != NULL);
fwrite(res,sizeof(int),n,fw);
fclose(fw);
free(res);
clock_t c2 = clock();
return c2-c1;
}
int Memoryfunction(int n)
{
int* res = (int*)calloc(n,sizeof(int));
assert(res != NULL);
int* p = (int*)calloc(n, sizeof(int));
assert(p != NULL);
for (int i = 0; i < n; i++)
{
res[i] = i;
}
clock_t c3 = clock();
memcpy(p, res, n * sizeof(int));
clock_t c4 = clock();
free(res);
free(p);
return c4 - c3;
}
int main()
{
int n = 250000000;
printf("%d\n", filefunction(n));
printf("%d\n", Memoryfunction(n));
return 0;
}