[Moscow.pm] Загрузка .PMC-файлов
Anton Nikishaev
anton.nik на gmail.com
Ср Июн 30 13:59:30 PDT 2010
Walery Studennikov <despairr на gmail.com>
writes:
>> #include <sys/types.h>
>> #include <sys/stat.h>
>> #include <sys/time.h>
>> #include <unistd.h>
>> #include <stdio.h>
>> int main()
>> {
>> int i;
>> struct stat s;
>> struct timeval t1, t2;
>> gettimeofday(&t1, NULL);
>> for ( i = 0; i < 10500; i++) stat("unexistent.pmc", &s);
>> gettimeofday(&t2, NULL);
>> i = t2.tv_sec * 1000000 + t2.tv_usec - t1.tv_sec * 1000000 - t1.tv_usec;
>> printf("%g seconds\n", (float)(i)/1000000);
>> return 0;
>> }
>>
>> аж целых 0.023536 seconds на моем медленном лаптопе )
>
> А ты имена файлов генерируй случайным образом -- так честнее будет ;)
#include <sys/stat.h>
#include <stdio.h>
int
main ()
{
for (int i = 0; i < 10000; i++)
{
char file[16];
sprintf (file, "file-%d.pmc", i);
struct stat info;
stat (file, &info);
}
}
lelf на Betty:~/hacking$ time ./a.out
real 0m0.073s
user 0m0.024s
sys 0m0.012s
Так что не в этом дело. А premature optimization is … ;-)
--
lelf xmpp:nik_n на jabber.ru
Подробная информация о списке рассылки Moscow-pm