virtual void on_ctrl_change() { if(m_test.status()) { on_draw(); update_window(); m_test.status(false); start_timer(); int i; for(i = 0; i < 1000; i++) { draw_aliased(); } double t1 = elapsed_time(); start_timer(); for(i = 0; i < 1000; i++) { draw_anti_aliased(); } double t2 = elapsed_time(); update_window(); char buf[100]; sprintf(buf, "Time Aliased=%.2fms Time Anti-Aliased=%.2fms", t1, t2); message(buf); } }
// encode function calls void encode(const char* type, const char* infilename, const char* outfilename) { infile = fopen(infilename, "r+b"); outfile = fopen(outfilename, "w+b"); printf("filename %s\n", infilename); //printf("size %d\n", get_file_size(infilename)); printf("----\n"); if ( strcmp(type, "HUFF") == 0 ) { start_timer(); huff(infile, outfile); printf("t-cmprss %.2f\n", elapsed_time()); } else if ( strcmp(type, "LZ1") == 0 ) { start_timer(); lz1(infile, outfile); printf("t-cmprss %.2f\n", elapsed_time()); } else if ( strcmp(type, "LZ2") == 0 ) { start_timer(); lz2(infile, outfile); printf("t-cmprss %.2f\n", elapsed_time()); } else printf("Error: unknown encode function call"); }
virtual void on_ctrl_change() { if(m_benchmark.status()) { int i; on_draw(); update_window(); scanline_rasterizer ras; pixfmt pixf(rbuf_window()); base_renderer rb(pixf); solid_renderer solid(rb); draft_renderer draft(rb); char buf[256]; if(m_draft.status()) { start_timer(); for(i = 0; i < 10; i++) { draw_scene(ras, solid, draft); } sprintf(buf, "%3.3f milliseconds", elapsed_time()); } else { double times[5]; for(m_draw = 0; m_draw < 4; m_draw++) { start_timer(); for(i = 0; i < 10; i++) { draw_scene(ras, solid, draft); } times[m_draw] = elapsed_time(); } m_draw = 3; times[4] = times[3]; times[3] -= times[2]; times[2] -= times[1]; times[1] -= times[0]; FILE* fd = fopen(full_file_name("benchmark"), "a"); fprintf(fd, "%10.3f %10.3f %10.3f %10.3f %10.3f\n", times[0], times[1], times[2], times[3], times[4]); fclose(fd); sprintf(buf, " pipeline add_path sort render total\n" "%10.3f %10.3f %10.3f %10.3f %10.3f", times[0], times[1], times[2], times[3], times[4]); } message(buf); m_benchmark.status(false); force_redraw(); } }
static void random_bench (int very_strong) { char buf[128]; int i; printf ("%-10s", "random"); if (!very_strong) { start_timer (); for (i=0; i < 100; i++) gcry_randomize (buf, sizeof buf, GCRY_STRONG_RANDOM); stop_timer (); printf (" %s", elapsed_time ()); } start_timer (); for (i=0; i < 100; i++) gcry_randomize (buf, 8, very_strong? GCRY_VERY_STRONG_RANDOM:GCRY_STRONG_RANDOM); stop_timer (); printf (" %s", elapsed_time ()); putchar ('\n'); if (verbose) gcry_control (GCRYCTL_DUMP_RANDOM_STATS); }
void t_move_missile::on_idle() { t_uint32 new_time = get_time(); // update animation (if any) if (elapsed_time( new_time, m_last_update_time ) >= m_delay ) { int frame = m_missile.get_current_frame_num(); frame++; if (frame >= m_missile.get_frame_count()) frame = 0; m_battlefield.set_current_frame_num( m_missile, frame ); m_last_update_time = new_time; } t_map_point_3d position; t_uint32 next_time = get_next_time() - get_delay(); int skip_limit = 1; // move missile forward one space while (elapsed_time( new_time, next_time ) >= 0 && skip_limit-- > 0 ) { next_time += get_delay(); if (m_distance_left <= 0) { t_idle_ptr reference = this; suspend_idle_processing(); m_battlefield.remove_object( &m_missile ); animation_ended(); m_end_handler( m_attacker, m_target_position ); return; } t_map_point_3d delta; int distance; // limit distance moved to distance left position = m_missile.get_position(); distance = m_move_distance; if (distance > m_distance_left) distance = m_distance_left; m_distance_left -= distance; // add distance to accumulator m_sum += m_delta * distance; // find integer portion of moved distance delta = m_sum / m_distance; position += delta; m_sum -= delta * m_distance; // calculate parabolic arc if (m_is_parabolic) { position.height += m_vertical_velocity - k_gravity; m_vertical_velocity -= k_gravity << 1; } } set_next_time( next_time ); m_battlefield.move_object( m_missile, position ); }
void process_whale(int is_male, int id) { int num_males, num_females; pthread_mutex_lock(&mutex); if (is_male) { male_queue[male_position++] = id; sem_post(&male_avail); } else { female_queue[female_position++] = id; sem_post(&female_avail); } sem_getvalue(&male_avail, &num_males); sem_getvalue(&female_avail, &num_females); pthread_mutex_unlock(&mutex); int this_sex = (is_male) ? num_males : num_females; int opposite_sex = (is_male) ? num_females : num_males; if (opposite_sex) { if (!mate_pending) { pthread_mutex_lock(&mutex); mate_pending++; LOCKED_PRINTF("(t=%f) %d: %s\n", elapsed_time(), male_queue[male_head], "Found Mate"); LOCKED_PRINTF("(t=%f) %d: %s\n", elapsed_time(), female_queue[female_head], "Found Mate"); pthread_mutex_unlock(&mutex); } if (this_sex > 1) { // matchmaker while (mate_pending) { pthread_mutex_lock(&mutex); LOCKED_PRINTF("(t=%f) %d: %s\n", elapsed_time(), id, "Became MatchMaker"); sem_wait(&male_avail); sem_wait(&female_avail); LOCKED_PRINTF("(t=%f) %d: %s\n", elapsed_time(), male_queue[male_head], "Mated"); LOCKED_PRINTF("(t=%f) %d: %s\n", elapsed_time(), female_queue[female_head], "Mated"); mate_pending--; male_head++; female_head++; pthread_mutex_unlock(&mutex); } pthread_mutex_lock(&mutex); sem_getvalue(&male_avail, &num_males); sem_getvalue(&female_avail, &num_females); pthread_mutex_unlock(&mutex); } } }
void perform_rendering(Scanline &sl, Ras &ras, Ren &ren, Clp &clp) { if(m_operation.cur_item() > 0) { ras.reset(); switch(m_operation.cur_item()) { case 1: clp.operation(agg::clipper_or); break; case 2: clp.operation(agg::clipper_and); break; case 3: clp.operation(agg::clipper_xor); break; case 4: clp.operation(agg::clipper_a_minus_b); break; case 5: clp.operation(agg::clipper_b_minus_a); break; } agg::conv_poly_counter<Clp> counter(clp); start_timer(); counter.rewind(0); double t1 = elapsed_time(); ras.reset(); double x; double y; unsigned cmd; start_timer(); while(!agg::is_stop(cmd = counter.vertex(&x, &y))) { ras.add_vertex(x, y, cmd); } ren.color(agg::rgba(0.5, 0.0, 0, 0.5)); agg::render_scanlines(ras, sl, ren); double t2 = elapsed_time(); char buf[100]; sprintf_s(buf, "Contours: %d Points: %d", counter.m_contours, counter.m_points); agg::gsv_text txt; agg::conv_stroke<agg::gsv_text> txt_stroke(txt); txt_stroke.width(1.5); txt_stroke.line_cap(agg::round_cap); txt.size(10.0); txt.start_point(250, 5); txt.text(buf); ras.add_path(txt_stroke); ren.color(agg::rgba(0.0, 0.0, 0.0)); agg::render_scanlines(ras, sl, ren); sprintf_s(buf, "Clipper=%.3fms Render=%.3fms", t1, t2); txt.start_point(250, 20); txt.text(buf); ras.add_path(txt_stroke); ren.color(agg::rgba(0.0, 0.0, 0.0)); agg::render_scanlines(ras, sl, ren); } }
/** @internal * @brief Calculates the RTT of the host with SSH channel operations, and * returns the average of the calculated RTT. * @param[in] session active SSH session to test. * @param[out] average average RTT in milliseconds. * @returns 0 on success, -1 if there is an error. */ int benchmarks_ssh_latency(ssh_session session, float *average){ float times[3]; struct timestamp_struct ts; int i; ssh_channel channel; channel=ssh_channel_new(session); if(channel==NULL) goto error; if(ssh_channel_open_session(channel)==SSH_ERROR) goto error; for(i=0;i<3;++i){ timestamp_init(&ts); if(ssh_channel_request_env(channel,"TEST","test")==SSH_ERROR && ssh_get_error_code(session)==SSH_FATAL) goto error; times[i]=elapsed_time(&ts); } ssh_channel_close(channel); ssh_channel_free(channel); channel=NULL; printf("Times : %f ms ; %f ms ; %f ms\n", times[0], times[1], times[2]); *average=(times[0]+times[1]+times[2])/3; return 0; error: fprintf(stderr,"Error calculating SSH latency : %s\n",ssh_get_error(session)); if(channel) ssh_channel_free(channel); return -1; }
initialize::~initialize() { if (!quiet) master_printf("\nElapsed run time = %g s\n", elapsed_time()); #ifdef HAVE_MPI end_divide_parallel(); MPI_Finalize(); #endif }
void perform_rendering(VertexSource& vs) { pixfmt_type pixf(rbuf_window()); typedef agg::pixfmt_amask_adaptor<pixfmt_type, alpha_mask_type> pixfmt_amask_type; typedef agg::renderer_base<pixfmt_amask_type> amask_ren_type; pixfmt_amask_type pixfa(pixf, m_alpha_mask); amask_ren_type rbase(pixfa); agg::renderer_scanline_aa_solid<amask_ren_type> ren(rbase); ren.color(agg::rgba(0.5, 0.0, 0, 0.5)); start_timer(); m_ras.reset(); m_ras.add_path(vs); agg::render_scanlines(m_ras, m_sl, ren); double t1 = elapsed_time(); char buf[100]; sprintf(buf, "Render with AlphaMask: %.3fms", t1); draw_text(250, 5, buf); }
template<class VertexSource> void generate_alpha_mask(VertexSource& vs) { unsigned cx = (unsigned)width(); unsigned cy = (unsigned)height(); delete [] m_alpha_buf; m_alpha_buf = new unsigned char[cx * cy]; m_alpha_mask_rbuf.attach(m_alpha_buf, cx, cy, cx); typedef agg::renderer_base<agg::pixfmt_gray8> ren_base; typedef agg::renderer_scanline_aa_solid<ren_base> renderer; agg::pixfmt_gray8 pixf(m_alpha_mask_rbuf); ren_base rb(pixf); renderer ren(rb); start_timer(); if(m_operation.cur_item() == 0) { rb.clear(agg::gray8(0)); ren.color(agg::gray8(255)); } else { rb.clear(agg::gray8(255)); ren.color(agg::gray8(0)); } m_ras.add_path(vs); agg::render_scanlines(m_ras, m_sl, ren); double t1 = elapsed_time(); char buf[100]; sprintf(buf, "Generate AlphaMask: %.3fms", t1); draw_text(250, 20, buf); }
/*** * Print out an optional message followed by the current timer timing. */ void Timer::check(const char* msg) { // Print an optional message, something like "Checking timer t"; if (msg) VERBOSE(0, msg << " : "); VERBOSE(0, "[" << (running ? elapsed_time() : 0) << "] seconds\n"); }
static void do_powm ( const char *n_str, const char *e_str, const char *m_str) { gcry_mpi_t e, n, msg, cip; gcry_error_t err; int i; err = gcry_mpi_scan (&n, GCRYMPI_FMT_HEX, n_str, 0, 0); if (err) BUG (); err = gcry_mpi_scan (&e, GCRYMPI_FMT_HEX, e_str, 0, 0); if (err) BUG (); err = gcry_mpi_scan (&msg, GCRYMPI_FMT_HEX, m_str, 0, 0); if (err) BUG (); cip = gcry_mpi_new (0); start_timer (); for (i=0; i < 1000; i++) gcry_mpi_powm (cip, msg, e, n); stop_timer (); printf (" %s", elapsed_time ()); fflush (stdout); /* { */ /* char *buf; */ /* if (gcry_mpi_aprint (GCRYMPI_FMT_HEX, (void**)&buf, NULL, cip)) */ /* BUG (); */ /* printf ("result: %s\n", buf); */ /* gcry_free (buf); */ /* } */ gcry_mpi_release (cip); gcry_mpi_release (msg); gcry_mpi_release (n); gcry_mpi_release (e); }
void obj::scene::initialize() { glClearColor(.1, .16, .19, 0); glClearDepth(1.0); GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; glShadeModel(GL_SMOOTH); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); glLineWidth(3); glPointSize(20); glScalef(2, 2, 5); glutSetCursor(GLUT_CURSOR_CROSSHAIR); current_time = timebase = elapsed_time(); camera = new obj::camera(90); reset_camera(); }
void benchmark(Graf& cos, int poczatek, int koniec, std::ostream& out) { std::chrono::time_point<std::chrono::system_clock> start, end; std::chrono::duration<double> elapsed_time(0); start = std::chrono::system_clock::now(); auto list = depth_first(cos, poczatek, koniec); end = std::chrono::system_clock::now(); elapsed_time = end-start; out << "DEPTH-FIRST time: " << elapsed_time.count() << "s. "; for( auto t : list ) std::cerr << t << " -> "; std::cerr << "\n"; start = std::chrono::system_clock::now(); list = breadth_first(cos, poczatek, koniec); end = std::chrono::system_clock::now(); elapsed_time = end-start; out << "BREADTH-FIRST time: " << elapsed_time.count() << "s. "; for( auto t : list ) std::cerr << t << " -> "; std::cerr << "\n"; start = std::chrono::system_clock::now(); list = a_star(cos, poczatek, koniec ); end = std::chrono::system_clock::now(); elapsed_time = end-start; out << "A* time: " << elapsed_time.count() << "s. "; for( auto t : list ) std::cerr << t << " -> "; std::cerr << "\n"; }
double remaining_time( double dist_thresh=Config::get_var_dbl("GEST_STARTUP_DIST_THRESH",10.0,true) ) const { // Time spent after the "startup" period within the given // distance of the 1st point. return elapsed_time() - startup_time(dist_thresh); }
main(){ struct timeval start,end; gettimeofday(&start, 0); int t,i,T,N,C,*P,*W; const int num_thread = 2; scanf("%d",&T); for(t=0;t<T;++t){ scanf("%d",&C); scanf("%d",&N); P = (int*)malloc(sizeof(int) * N); W = (int*)malloc(sizeof(int) * N); for(i=0;i<N;++i){ scanf("%d %d",&W[i],&P[i]); } printf("%d\n",p_knapsack(num_thread,P,W,N,C)); } gettimeofday(&end, 0); printf("%lf\n", elapsed_time(start,end)); }
int main(int argc, char *argv[]) { ticks_per_second = sysconf(_SC_CLK_TCK); if((argc !=2 && argc !=3) || (argv[1][0] == '-' && argv[1][1] == 'h')){ printf("usage: ./MixBcd CNF formula [<output>]\n"); return 0; } printf("c MixBcd: Fast blocked clause decomposition by Chen, July 1, 2015\n"); fileName = argv[1]; if (argc == 3) output = fopen(argv[2], "w"); else output = stdout; buildSignalHandler(); readCNFfile(); value = (int*) malloc(sizeof(int) * (nVars + 1)); lookup_Mem(); MixDecompose(0); double totalTime = elapsed_time(); printf("c %-30s: %-8.3fsec\n", "final time", totalTime); return 0; }
void on_idle() { if(m_run.status()) { if(m_cur_angle < 360.0) { m_cur_angle += m_step.value(); copy_img_to_img(1, 0); #ifdef AGG_ACCURATE_TIME start_timer(); #endif transform_image(m_step.value()); #ifdef AGG_ACCURATE_TIME m_time2 += elapsed_time(); #endif m_num_steps++; } else { m_cur_angle = 0.0; #ifndef AGG_ACCURATE_TIME m_time2 = clock(); #endif wait_mode(true); m_run.status(false); } force_redraw(); } else { wait_mode(true); } }
void propose_value_instrumented() { int i; int rt; int tot = 0; int min = INT_MAX; int max = 0; struct timeval t1, t2; for (i = 0; i < values_to_propose; i++) { generate_random_val(buffer, value_size); gettimeofday(&t1, NULL); proposer_submit_value(buffer, value_size); gettimeofday(&t2, NULL); rt = elapsed_time(&t1, &t2); if (rt < min) min = rt; if (rt > max) max = rt; tot += rt; if ((i % (values_to_propose/10)) == 0) { printf("Proposed %d values\n", i); } } printf("Proposed %d values\n", i); printf("Min: %d\n", min); printf("Max: %d\n", max); printf("Avg: %d\n", tot / values_to_propose); }
virtual void on_mouse_button_down(int x, int y, unsigned flags) { if(flags & agg::mouse_left) { if(m_quad.on_mouse_button_down(x, y)) { force_redraw(); } else { start_timer(); m_test_flag = true; on_draw(); on_draw(); on_draw(); on_draw(); char buf[100]; sprintf(buf, "time=%.3f", elapsed_time()); m_test_flag = false; force_redraw(); message(buf); } } }
void writeGeotiff() { ros::Time start_time (ros::Time::now()); std::stringstream ssStream; nav_msgs::GetMap srv_map; if (map_service_client_.call(srv_map)) { ROS_INFO("GeotiffNode: Map service called successfully"); const nav_msgs::OccupancyGrid& map (srv_map.response.map); std::string map_file_name = p_map_file_base_name_; std::string competition_name; std::string team_name; std::string mission_name; std::string postfix; if (n_.getParamCached("/competition", competition_name) && !competition_name.empty()) map_file_name = map_file_name + "_" + competition_name; if (n_.getParamCached("/team", team_name) && !team_name.empty()) map_file_name = map_file_name + "_" + team_name; if (n_.getParamCached("/mission", mission_name) && !mission_name.empty()) map_file_name = map_file_name + "_" + mission_name; if (pn_.getParamCached("map_file_postfix", postfix) && !postfix.empty()) map_file_name = map_file_name + "_" + postfix; if (map_file_name.substr(0, 1) == "_") map_file_name = map_file_name.substr(1); if (map_file_name.empty()) map_file_name = "GeoTiffMap"; geotiff_writer_.setMapFileName(map_file_name); bool transformSuccess = geotiff_writer_.setupTransforms(map); if(!transformSuccess){ ROS_INFO("Couldn't set map transform"); return; } geotiff_writer_.setupImageSize(); if (p_draw_background_checkerboard_){ geotiff_writer_.drawBackgroundCheckerboard(); } geotiff_writer_.drawMap(map, p_draw_free_space_grid_); geotiff_writer_.drawCoords(); //ROS_INFO("Sum: %ld", (long int)srv.response.sum); } else { ROS_ERROR("Failed to call map service"); return; } for (size_t i = 0; i < plugin_vector_.size(); ++i){ plugin_vector_[i]->draw(&geotiff_writer_); } geotiff_writer_.writeGeotiffImage(); running_saved_map_num_++; ros::Duration elapsed_time (ros::Time::now() - start_time); ROS_INFO("GeoTiff created in %f seconds", elapsed_time.toSec()); }
tracer_emitter::~tracer_emitter() { if (!m_exit_written) { write_tracer(false); elapsed_time(); // just for the side effect of logging if needed } }
TEST_F(SemaphoreTest, timedwait) { semaphore->post(); ASSERT_TRUE(semaphore->timedwait(0.1)); Time start_time(Time::now()); semaphore->timedwait(0.1); Time elapsed_time(Time::now() - start_time); ASSERT_GE(elapsed_time, Time(0.1)); }
void BytecodeCounter::print() { tty->print_cr( "%d bytecodes executed in %.1fs (%.3fMHz)", counter_value(), elapsed_time(), frequency() / 1000000.0 ); }
uint64_t tracer_emitter::stop() { ASSERT(!m_exit_written); if (!m_exit_written) { write_tracer(false); } return elapsed_time(); }
void timer_stop( int n ) { double t, now; now = elapsed_time(); t = now - start[n]; elapsed[n] += t; }
void timer_start( int n ) { // ADJUSTED!! // start[n] = elapsed_time(); double et; et = elapsed_time(); start[n] = et; }
int main (int argc, char **argv) { int last_argc = -1; if (argc) { argc--; argv++; } while (argc && last_argc != argc ) { last_argc = argc; if (!strcmp (*argv, "--")) { argc--; argv++; break; } else if (!strcmp (*argv, "--help")) { fputs ("usage: " PGM " [options]\n" "Options:\n" " --verbose print timings etc.\n" " --debug flyswatter\n", stdout); exit (0); } else if (!strcmp (*argv, "--verbose")) { verbose++; argc--; argv++; } else if (!strcmp (*argv, "--debug")) { verbose += 2; debug++; argc--; argv++; } else if (!strncmp (*argv, "--", 2)) die ("unknown option '%s'", *argv); } xgcry_control (GCRYCTL_DISABLE_SECMEM, 0); if (!gcry_check_version (GCRYPT_VERSION)) die ("version mismatch\n"); if (debug) xgcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0); xgcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); xgcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); start_timer (); check_cv25519 (); stop_timer (); info ("All tests completed in %s. Errors: %d\n", elapsed_time (1), error_count); return !!error_count; }
//////////////////////////////////////////////////////////////////////////////// // Program main //////////////////////////////////////////////////////////////////////////////// int main( int argc, char** argv) { init_timer(timer_ctrl, timer_counter_l, timer_counter_h); start_timer(timer_ctrl); // run test runTest( argc, argv); stop_timer(timer_ctrl); printf("Execution time %lld us\n\r", elapsed_time()); }