Sunum yükleniyor. Lütfen bekleyiniz

Sunum yükleniyor. Lütfen bekleyiniz

Paralel Programlamaya Giriş 2

Benzer bir sunumlar


... konulu sunumlar: "Paralel Programlamaya Giriş 2"— Sunum transkripti:

1 Paralel Programlamaya Giriş 2

2 YAZDIĞIMIZ C++ PROGRAMLARININ PERFORMANSININ ÖLÇÜLMESİ
Yazdığımız ve executable haline dönüştürdüğümüz C++ programlarımızın CPU tarafından ne kadar bir sürede işletildiğini bizim için hesaplayan time adında bir Linux komutu vardır. time komutuna argüman olarak çalıştıracağımız executable dosyanın adını ve varsa eğer dosyanın komut satırı parametrelerini vermeliyiz. Örnek: $man time Örnek: $time ./a.out Örnek: $time ./deneme.x Örnek: $time ./deneme.x 100 Örnek: $time ./deneme.x -n 100 ÖRNEK ÇIKTI real 0m2.398s user 0m2.376s sys 0m0.018s

3 time KOMUTU ÇIKTISI real
Programın çalıştırılmaya başlandığı an ile çalışmasının bittiği an arasında geçen reel süredir. (Wall Clock Time) (Executable dosyanızın harddiskten belleğe getirilmesi de süre alır.) user CPU’nun kullanıcının işini gerçekleştirmek üzere harcadığı zaman. (CPU Time) sys Sistem tarafından kullanılan toplam CPU süresi. (İşletim sisteminin sizin programınızı işletirken harcadığı CPU zamanı. Örneğin I/O işlemlerinin gerçekleştirilmesi.)

4 C++ Programlarında Zaman Ölçümü (Windows)
#include <ctime>//clock_t, clock() ve CLOCKS_PER_SECOND #include <iostream>//cout using namespace std; int main(int argc, char* argv[ ]) { clock_t baslangicZamani, bitisZamani; double gecenZaman; baslangicZamani=clock(); ////Süresini Ölçmek İstediğiniz Program Burada//// bitisZamani=clock(); gecenZaman=((double)bitisZamani -(double)baslangicZamani)/CLOCKS_PER_SEC; cout<< "Total Time Taken (saniye cinsinden): " <<gecenZaman<<endl; return 0; }

5 C++ Programlarında Zaman Ölçümü (Linux)
#include <sys/time.h>//struct timeval #include <iostream>//cout using namespace std; int main(int argc, char* argv[ ]) { struct timeval currentTime; double startTime,endTime,elapsedTime; // Get the current time. 2nd argument NULL because we don't care about time zone gettimeofday(&currentTime, NULL); //Seconds from the epoch time startTime=currentTime.tv_sec+(currentTime.tv_usec/ ); ////Süresini Ölçmek İstediğiniz Program Burada//// // Get the current time endTime=currentTime.tv_sec+(currentTime.tv_usec/ ); // Calculate the elapsed time in seconds elapsedTime = endTime-startTime; cout << "Total Time Taken (saniye cinsinden): " << elapsedTime<< endl; return 0; } int gettimeofday(timeval *tp, NULL) include: <sys/time.h> Note In C programs (as opposed to C++) the word "struct" must appear before "timeval". Gets the time of day. The parameter must be a pointer to a previously declared timeval variable (or in C, a struct timeval variable). This struct type is also defined in <sys/time.h>. A timeval has two components, both ints. One (called tv_sec) is exactly the value that would be returned by time, the time in seconds since 1/1/1970. The other (called tv_usec) is the number of microseconds into that second. Don't be fooled: although the units are microseconds, the value is nothing like that accurate. On many systems, is added 100 times per second. Example: timeval tim; gettimeofday(&tim, NULL); double t1=tim.tv_sec+(tim.tv_usec/ ); do_something_long(); gettimeofday(&tim, NULL); double t2=tim.tv_sec+(tim.tv_usec/ ); printf("%.6lf seconds elapsed\n", t2-t1); The second parameter (NULL) used to be to retrieve the local time zone, but time zones are no-longer handled that way.


"Paralel Programlamaya Giriş 2" indir ppt

Benzer bir sunumlar


Google Reklamları