/** * @brief release_processor(). * @return RTX_ERR on error and zero on success * POST: gp_current_process gets updated to next to run process */ int k_release_processor(void) { PCB *p_pcb_old = NULL; int time; #ifdef TIMING start_timer(); #endif if (gp_current_process != NULL && gp_current_process->m_priority < pq_peak(ready_queue)->m_priority && gp_current_process->m_state!=BLK && gp_current_process->m_state!=BLK_RCV) { #ifdef DEBUG_0 //printf("remaining on process %d\n", gp_current_process->m_pid); #endif /* ! DEBUG_0 */ return RTX_OK; } p_pcb_old = gp_current_process; gp_current_process = scheduler(); if ( gp_current_process == NULL ) { gp_current_process = p_pcb_old; // revert back to the old process return RTX_ERR; } if ( p_pcb_old == NULL) { p_pcb_old = gp_current_process; } process_switch(p_pcb_old); #ifdef TIMING time = end_timer(); #endif return RTX_OK; }
static void async_test(const char *fname, int block_size, int nblocks, int rsize) { int fd; struct aio_ring *ring; off_t offset=0; char buf[rsize]; int i=0; offset=0; start_timer(); fd = open(fname, O_RDONLY); if (fd == -1) { perror(fname); exit(1); } ring = a_init(fd, block_size, nblocks); if (ring == NULL) { fprintf(stderr, "a_init faild\n"); exit(1); } while (a_read(ring, buf, sizeof(buf), offset) > 0) { offset += sizeof(buf); if (++i % 5 == 0) { offset -= 2*sizeof(buf); } } printf("async: %.3f MByte/sec\n", 1.0e-6 * offset / end_timer()); a_close(ring); }
int main(int argc, char**argv){ char * evar = getenv("RELY_SRAND_DATA"); if(evar != NULL) srand(atoi(evar)); else srand(0); if(argc <= 3){ printf("USAGE: scale FACTOR INPUT OUTPUT\n"); return 1; } inst_timer GLOBAL_TIMER = create_timer(); start_timer(&GLOBAL_TIMER); double scale_factor = atof(argv[1]); char* in_filename = argv[2]; char * out_filename = argv[3]; printf("scale by %f: %s -> %s\n", scale_factor, in_filename, out_filename); int* src, * transformed; size_t sw, sh, dw, dh; printf("read from \"%s\" ...\n", in_filename); src = read_image(in_filename, &sw, &sh); if(src == NULL){ fprintf(stderr, ">> Failed to read image %s\n", in_filename); exit(1); } transformed = allocate_transform_image(scale_factor, sw, sh, &dw, &dh); scale(scale_factor, src, sw, sh, transformed, dw, dh); printf("write to \"%s\" ...\n", out_filename); write_image(out_filename, transformed, dw, dh); free((void *) src); free((void *) transformed); end_timer(&GLOBAL_TIMER); printf("GLOBAL TIME\n"); print_timer(&GLOBAL_TIMER); }
int k_set_process_priority(int pid, int prio){ PCB *p; int time; #ifdef TIMING start_timer(); #endif // TODO: add check if (pid == PID_NULL || pid == PID_TIMER_IPROC || pid == PID_UART_IPROC || prio < HIGH || prio > LOWEST) { return RTX_ERR; } p = get_process(pid, gp_pcbs); if (p == NULL) { return RTX_ERR; } #ifdef DEBUG_0 printf("setting process %d priority from %d to %d\n", p->m_pid, p->m_priority, prio); #endif /* ! DEBUG_0 */ p->m_priority = prio; pq_sort(ready_queue); check_priority(); #ifdef TIMING time = end_timer(); #endif return RTX_OK; }
void imagetext16_test(void) { int num_strings = 50; int i; long totaltime; char buf[80]; num_strings *= X.percent; GC_change_font(unicode_font,FALSE); XSync(X.dpy,0); start_timer(); for (i=0;i<num_strings;++i) { XDrawImageString16(X.dpy,X.win,X.gc,(i%2 ? i : num_strings - i),10*i, string16,sizeof(string16)/sizeof(XChar2b)); } XSync(X.dpy,0); totaltime = end_timer(); GC_change_font(X.fontname,FALSE); snprintf(buf,sizeof buf,"%d strings in %.2f seconds.",num_strings, (double) totaltime/1000000.); show_result(buf); }
int main (int argc, char** argvs) { struct timeval total_start,start, end; // Check number of arguments if (argc != 2 && argc != 3) { printf("Expected at least 1 argument to commandline.\n"); exit(-1); } //Read in AST char* filename = argvs[1]; ScopeStmt* stmt = read_ast(filename); //Compile to bytecode Program* program = compile(stmt); if(argc == 3){ start_timer("interpret_time"); } //Interpret bytecode interpret_bc(program); if(argc == 3){ FILE* stat = fopen(argvs[2], "w"); end_timer("interpret_time"); fprintf(stat, "interpret: %f\n", get_double("interpret_time")); fprintf(stat, "General or slot lookup count: %ld\n", get_int("lookup_count")); fclose(stat); } return 0; }
void genericarc_test(Boolean fill) { XArc *arcs; int num_arcs = 180; int i; long totaltime; char buf[80]; num_arcs *= X.percent; arcs = (XArc *) malloc(sizeof(XArc) * num_arcs); for (i=0;i<num_arcs;++i) { arcs[i].x = i; arcs[i].y = i; arcs[i].width = i; arcs[i].height = i; arcs[i].angle1 = i * 128; arcs[i].angle2 = i * 128; } XSync(X.dpy,0); start_timer(); if (fill) XFillArcs(X.dpy,X.win,X.gc,arcs,num_arcs); else XDrawArcs(X.dpy,X.win,X.gc,arcs,num_arcs); XSync(X.dpy,0); totaltime = end_timer(); snprintf(buf,sizeof buf,"An uncounted number of pixels in %.3f seconds.", (double)totaltime/1000000.); show_result(buf); free(arcs); }
void polypoint_test(void) { XPoint *points; int num_points = 100000; long totaltime; char buf[80]; int i; num_points *= X.percent; points = (XPoint *) malloc(sizeof(XPoint) * num_points); points[0].x = random()%400; points[0].y = random()%400; points[1].x = random()%400; points[1].y = random()%400; for (i=2;i<num_points;++i) { points[i].x = (points[i-1].x+points[i-2].y+i*3/200)%400; points[i].y = (points[i-1].y+points[i-2].x+i*5/200)%400; } XSync(X.dpy,0); start_timer(); XDrawPoints(X.dpy,X.win,X.gc,points,num_points,CoordModeOrigin); XSync(X.dpy,0); totaltime = end_timer(); snprintf(buf,sizeof buf,"%d points in %.3f seconds.",num_points, (double)totaltime/1000000.); show_result(buf); free(points); }
void polysegment_test(void) { XSegment *segments; int num_segments = 600; long totaltime; char buf[80]; int i; num_segments *= X.percent; segments = (XSegment *) malloc(sizeof(XSegment) * num_segments); segments[0].x1 = random()%400; segments[0].y1 = random()%400; segments[0].x2 = random()%400; segments[0].y2 = random()%400; for(i=1;i<num_segments;++i) { segments[i].x1 = (segments[i-1].x1-segments[i-1].y2+400+i)%400; segments[i].y1 = (segments[i-1].y1+segments[i-1].x2+i)%400; segments[i].x2 = (segments[i-1].x1-segments[i-1].y1+400+i)%400; segments[i].y2 = (segments[i-1].x2+segments[i-1].y2+i)%400; } XSync(X.dpy,0); start_timer(); XDrawSegments(X.dpy,X.win,X.gc,segments,num_segments); XSync(X.dpy,0); totaltime = end_timer(); snprintf(buf,sizeof buf,"%d segments in %.3f seconds.",num_segments, (double)totaltime/1000000.); show_result(buf); free(segments); }
void LBCSolver::solve() { if(!valid_init_data_){ std::cerr << "Invalid data, unable to solve...." << std::endl; return; } initialize_variables(); start_timer(); int iter = 0; optimization_end_ = false; while (!optimization_end_) { iter++; check_convergence_ = (iter % convergence_check_frequency_ == 0 || iter >= param_.max_iterations); output_progress_ = (iter % output_frequency_ == 0 ); #pragma omp parallel { this->update_x(); this->update_w(); this->update_y(); this->update_dual_variables(iter); } } end_timer(); show_elapsed_time(); }
int main() { #if __STDC__ == 1 printf("This is Ansi C standardized\r\n"); char return_key; double start_of_the_timer,end_of_the_timer,time_in_minutes,time_in_hours; start_of_the_timer = start_timer(); printf("Timer started, press enter to get time since start of program\r\n"); return_key=getchar(); end_of_the_timer = end_timer(start_of_the_timer); printf("%lf was the number of seconds since you pressed enter\r\n",end_of_the_timer); time_in_minutes = minutes(end_of_the_timer); printf("%lf was the number of minutes since being stopped\r\n",time_in_minutes); time_in_hours = hours(time_in_minutes); printf("%lf was the number of hours since being stopped\r\n",time_in_hours); return 0; #else printf("This is not Ansi C standardized\r\n"); return 0; #endif }
static void sync_test(const char *fname, int rsize) { int fd; off_t offset=0; char buf[rsize]; int i=0; offset=0; start_timer(); fd = open(fname, O_RDONLY); if (fd == -1) { perror(fname); exit(1); } while (pread(fd, buf, sizeof(buf), offset) > 0) { offset += sizeof(buf); if (++i % 5 == 0) { offset -= 2*sizeof(buf); } } printf("sync : %.3f MByte/sec\n", 1.0e-6 * offset / end_timer()); close(fd); }
int c_link::handle_timeout( void* data ) { if(m_timer_event == TE_PLAYER_DOING_LINK){ return notify_game_over(); } end_timer(true); return -1; }
int main(int argc, char *argv[]) { long befehle_array[LEN_ALGORITHMEN][LEN_WERTE]; long werte_array[LEN_ALGORITHMEN][LEN_WERTE]; double laufzeit_array[LEN_ALGORITHMEN][LEN_WERTE]; for(int j = 0; j < LEN_WERTE; ++j) { int n = WERTE[j]; for(int i = 0; i < LEN_ALGORITHMEN; ++i) { printf("Starte Algorithmus %d mit Wert %d\n", (i+1), n); int anzahl_befehle = 0; int wert = 0; //Starte den Timer start_timer(); //Aufruf der entsprechenden Funktion if(i==0) { wert = for_linear(n, &anzahl_befehle); } else if(i==1) { wert = for_quadratisch(n, &anzahl_befehle); } else if(i==2) { wert = for_kubisch(n, &anzahl_befehle); } //speichere Laufzeit, Rückgabewert und Anzahl ausgeführter Befehle ab laufzeit_array[i][j] = end_timer(); werte_array[i][j] = wert; befehle_array[i][j] = anzahl_befehle; } printf("\n"); } //Ausgabe der Rückgabewerte, Anzahl ausgeführter Befehle sowie der gemessenen Laufzeiten (in Millisekunden) printf("%3s \t%28s \t%28s \t%28s\n", "","linear", "quadratisch", "kubisch"); printf("%3s \t %5s %10s %10s\t %5s %10s %10s\t %5s %10s %10s\n", "n","Wert","Befehle","Laufzeit","Wert","Befehle","Laufzeit","Wert","Befehle","Laufzeit"); for(int j = 0; j < LEN_WERTE; ++j) { printf("%3d \t ",WERTE[j]); for(int i = 0; i < LEN_ALGORITHMEN; ++i) { printf("%5ld %10ld %10.4f \t ", werte_array[i][j], befehle_array[i][j], laufzeit_array[i][j]); } printf("\n"); } return 0; }
int main() { //start_timer(); //printf("%d\n", sum(100000)); //end_timer(); start_timer(); printf("%d\n", fastsum(100000)); end_timer(); }
int main(int argc, char **argv) { int j; init_array(); start_timer(); simple(A); printf("A[0] = %d\n", A[0]); end_timer(); }
/* * This function read the partial result from the attack program. */ void read_result () { struct attack_partial_result result; read_data (&result, sizeof (result)); end_timer (); printf ("/ Results received\n"); dump_result_to_file (&result); }
static void write_file(char *fname) { int fd; static double total, thisrun; int n; char *buf; buf = malloc(block_size); if (!buf) { printf("Malloc of %d failed\n", (int)block_size); exit(1); } fd = open(fname, O_WRONLY|(osync?O_SYNC:0)); if (fd == -1) { perror(fname); free(buf); return; } while ((n = write(fd, buf, block_size)) > 0) { total += n; thisrun += n; if (end_timer() >= 1.0) { time_t t = time(NULL); printf("%6d MB %.3f MB/sec %s", (int)(total/1.0e6), (thisrun*1.0e-6)/end_timer(), ctime(&t)); start_timer(); thisrun = 0; } } free(buf); close(fd); }
static void worker(int port1, int port2, int w) { int l = tcp_socket_bind(port1); int s2, s1; int count=0; set_socket_options(l, "SO_REUSEADDR"); sleep(2); s2 = tcp_socket_connect(port2); s1 = tcp_socket_accept(l); set_socket_options(s1, "TCP_NODELAY"); set_socket_options(s2, "TCP_NODELAY"); start_timer(); while (1) { char c=0; if (write(s2, &c, 1) != 1) { fatal("write"); } if (read(s1, &c, 1) != 1) { fatal("read"); } if (w == 1 && (end_timer() > 1.0)) { printf("%8u ops/sec\r", (unsigned)(2*count/end_timer())); fflush(stdout); start_timer(); count=0; } count++; } }
int main(int argc, char **argv) { int i, j; init_array(); start_timer(); int total_sum, addr = B[0] & CAP_; for(i = 0; i < NUM_LOOKUPS; i ++) { total_sum += A[addr]; addr = (total_sum + B[i]) & CAP_; // Make every addr depend on the last one } printf("Total Sum = %d\n", total_sum); end_timer(); }
int k_get_process_priority(int pid){ int time; PCB *p = get_process(pid, gp_pcbs); #ifdef TIMING start_timer(); #endif #ifdef DEBUG_0 printf("getting priority for process %d\n", p->m_pid); #endif /* ! DEBUG_0 */ if (p == NULL) { return -1; } #ifdef TIMING time = end_timer(); #endif return p->m_priority; }
int process_random_batch( int no_random ) { #ifdef TARBIND_LOG_SEEKS_DEBUG lib1tquery_log_seeks_to( seeklog_randoms ); #endif begin_timer(); for(int i=0;i<no_random;i++) { lib1tquery_test_random_read(); } microseconds_on_random += random_batch[ random_batches++ ] = end_timer(); random_performed += no_random; #ifdef TARBIND_LOG_SEEKS_DEBUG lib1tquery_log_seeks_to( 0 ); #endif }
static void load_gen(int fd) { int *buf; unsigned pkts=0; unsigned i=0; unsigned max_recvd=0; buf = malloc(BUFSIZE); if (backlog) { set_nonblocking(fd); } start_timer(); while (1) { int n; buf[0] = htonl(recv_size); buf[1] = i++; write(fd, buf, send_size); n = read(fd, buf, BUFSIZE); if (n == recv_size) { pkts++; if (buf[1] > max_recvd) max_recvd = buf[1]; if (max_recvd > i) max_recvd = i; } if (backlog && i - max_recvd >= backlog) { fd_set fds; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 1; FD_ZERO(&fds); FD_SET(fd, &fds); select(fd+1, &fds, NULL, NULL, &tv); } if (end_timer() > 1.0) { report_time(pkts*(recv_size+send_size)); start_timer(); pkts=0; } } }
int main() { char return_key; double start_of_the_timer,end_of_the_timer,time_in_minutes,time_in_hours; start_of_the_timer = start_timer(); printf("Timer started, press enter to get time since start of program\r\n"); return_key=getchar(); end_of_the_timer = end_timer(start_of_the_timer); printf("%lf was the number of seconds since you pressed enter\r\n",end_of_the_timer); time_in_minutes = minutes(end_of_the_timer); printf("%lf was the number of minutes since being stopped\r\n",time_in_minutes); time_in_hours = hours(time_in_minutes); printf("%lf was the number of hours since being stopped\r\n",time_in_hours); return 0; }
static void attack_it(const char *target, int len) { int i; double totals[256]; double this_run[256]; char teststr[len+1]; int c, r, runs, min_c; double min; runs = 1000000; for (i=0;i<len;i++) { memset(totals, 0, sizeof(totals)); for (r=0;r<runs;r++) { for (c=0;c<256;c++) { start_timer(); teststr[i] = c; memcmp(teststr, target, i+1); this_run[c] = end_timer(); } for (c=0;c<256;c++) { // printf("%3d %lf\n", c, 1000*1000*this_run[c]); totals[c] += this_run[c]; } } min_c = 0; min = totals[0]; for (c=1;c<256;c++) { if (totals[c] < min) { min = totals[c]; min_c = c; } } printf("min_c=%d\n", min_c); } }
void imagetext8_test(void) { int num_strings = 200; int i; long totaltime; char buf[80]; num_strings *= X.percent; XSync(X.dpy,0); start_timer(); for (i=0;i<num_strings;++i) { XDrawImageString(X.dpy,X.win,X.gc,(i%2 ? i : num_strings - i),i, string8,sizeof(string8)-1); } XSync(X.dpy,0); totaltime = end_timer(); snprintf(buf,sizeof buf,"%d strings in %.2f seconds.",num_strings, (double) totaltime/1000000.); show_result(buf); }
static void sig_alarm(void) { double total = 0; int total_lines = 0; int running = 0; int i; int nprocs = children[0].nprocs; for (i=0;i<nprocs;i++) { total += children[i].bytes_in + children[i].bytes_out; total_lines += children[i].line; if (!children[i].done) running++; } /* yeah, I'm doing stdio in a signal handler. So sue me. */ printf("%4d %8d %.2f MB/sec\r", running, total_lines / nprocs, 1.0e-6 * total / end_timer()); fflush(stdout); #ifndef OS2 signal(SIGALRM, sig_alarm); alarm(PRINT_FREQ); #endif }
void genericrectangle_test(Boolean fill) { XRectangle *rects; int num_rects = 200; int perimeter = 0, area = 0; int i; long totaltime; char buf[80]; num_rects *= X.percent; rects = (XRectangle *) malloc(sizeof(XRectangle) * num_rects); for (i=0;i<num_rects;++i) { rects[i].x = rects[i].y = 200 - i; rects[i].width = rects[i].height = 2 * i; perimeter += rects[i].width * 2 + rects[i].height * 2; area += rects[i].width * rects[i].height; } XSync(X.dpy,0); start_timer(); if (fill) XFillRectangles(X.dpy,X.win,X.gc,rects,num_rects); else XDrawRectangles(X.dpy,X.win,X.gc,rects,num_rects); XSync(X.dpy,0); totaltime = end_timer(); if (fill) snprintf(buf,sizeof buf,"%d pixels in %.2f seconds.",area,(double)totaltime/1000000.); else snprintf(buf,sizeof buf,"Total line length %d in %.3f seconds.",perimeter, (double)totaltime/1000000.); show_result(buf); free(rects); }
int main(int argc, char *argv[]) { int nprocs; double t; double total_bytes = 0; int i; if (!process_opts(argc, argv, &nprocs)) show_usage(); t = create_procs(nprocs, child_run); for (i=0;i<nprocs;i++) { total_bytes += children[i].bytes_in + children[i].bytes_out; } t = end_timer(); printf("Throughput %g MB/sec%s%s %d procs\n", 1.0e-6 * total_bytes / t, sync_open ? " (sync open)" : "", sync_dirs ? " (sync dirs)" : "", nprocs); return 0; }
int process_query_batch( char *queries[][6], int no_queries ) { int32_t q[5]; #ifdef TARBIND_LOG_SEEKS_DEBUG lib1tquery_log_seeks_to( seeklog_queries ); #endif begin_timer(); for(int i=0;i<no_queries;i++) { int j = 0; while( queries[i][j] && j < 5) { q[j] = lib1tquery_dictionary( queries[i][j] ); j++; } if( queries[i][j] ) return 1; #ifdef DO_DEBUG fprintf( stderr, "query: " ); for(int k=0;k<j;k++) { fprintf( stderr, "%s ", queries[i][k] ); } fprintf( stderr, "\n" ); #endif lib1tquery_lookup_ngram( j, q ); } microseconds_on_queries += queries_batch[ queries_batches++ ] = end_timer(); queries_performed += no_queries; #ifdef TARBIND_LOG_SEEKS_DEBUG lib1tquery_log_seeks_to( 0 ); #endif return 0; }