Pagini recente » Profil Simon2712 | Atasamentele paginii Profil madalina234 | Profil Simon2712 | Profil Simon2712 | Cod sursa (job #293669)
Cod sursa(job #293669)
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <time.h>
using namespace std;
int n = 100000;
double start,stop;
int QWERTY = 1, LOL = 123456789;
void init()
{
QWERTY = 123456789;
}
int numar_random()
{
QWERTY += LOL;
return QWERTY;
}
double timp()
{
return (stop-start)/1000;
}
void test_scanf()
{
init();
//printf("test stdio.h\n");
//scriere
start = clock();
FILE *f = fopen("cutii.out","w");
int tmp;
long long suma=0;
for (int i=1;i<=n;++i)
{
tmp = numar_random();
suma += tmp;
fprintf(f,"%d\n", tmp);
}
fclose(f);
stop = clock();
//printf("a scris %d numere in %.2f secunde\n", n,timp());
//printf("suma lor este %lld\n", suma);
//citire
start = clock();
f = fopen("cutii.out","r");
suma = 0;
for (int i=1;i<=n;++i)
{
fscanf(f,"%d", &tmp);
suma += tmp;
}
fclose(f);
stop = clock();
//printf("a citit %d numere in %.2f secunde\n", n,timp());
//printf("suma lor este %lld\n", suma);
}
void test_streamuri()
{
init();
//printf("test streamuri\n");
//scriere
start = clock();
ofstream out("cutii.out");
int tmp;
long long suma=0;
for (int i=1;i<=n;++i)
{
tmp = numar_random();
suma += tmp;
out<<tmp<<'\n';
}
out.close();
stop = clock();
//citire
//printf("a scris %d numere in %.2f secunde\n", n,timp());
//printf("suma lor este %lld\n", suma);
start = clock();
ifstream in("cutii.out");
suma = 0;
for (int i=1;i<=n;++i)
{
in>>tmp;
suma += tmp;
}
in.close();
stop = clock();
//printf("a citit %d numere in %.2f secunde\n", n,timp());
//printf("suma lor este %lld\n", suma);
}
int main()
{
test_scanf();
//test_streamuri();
//scanf("\n");
return 0;
}