/*************************************************************************** * Copyright (C) 2004 by Epiphanov Sergei * * serpiph@nikiet.ru * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include void handler(int i){ return; } using namespace std; int main(int argc, char *argv[]) { //cout << "Hello, world!" << endl; struct timeval begin, end; struct timezone tz __attribute__ ((__unused__)); struct sigaction sa; memset( &sa, 0, sizeof( sa) ); sa.sa_handler = handler; sigaction( SIGALRM, &sa, NULL ); struct itimerval tv; tv.it_interval.tv_sec = 0; tv.it_interval.tv_usec = 60000; tv.it_value.tv_sec = 0; tv.it_value.tv_usec = 60000; setitimer( ITIMER_REAL, &tv, NULL ); gettimeofday( &begin, &tz); for( int i=0; i<100; i++){ pause(); cout << "Number=" << i << "\n"; } gettimeofday( &end, &tz); cout << "Execution time=" << (end.tv_sec-begin.tv_sec)+ ((float)end.tv_usec-(float)begin.tv_usec)/1e6<< " seconds\n"; tv.it_interval.tv_usec = 0; tv.it_value.tv_usec = 0; setitimer( ITIMER_REAL, &tv, NULL ); sa.sa_handler = SIG_DFL; sigaction( SIGALRM, &sa, NULL ); return EXIT_SUCCESS; }