void EdgeBasedGraphFactory::Run(const std::string &original_edge_data_filename, const std::string &geometry_filename, lua_State *lua_state) { TIMER_START(geometry); CompressGeometry(); TIMER_STOP(geometry); TIMER_START(renumber); RenumberEdges(); TIMER_STOP(renumber); TIMER_START(generate_nodes); GenerateEdgeExpandedNodes(); TIMER_STOP(generate_nodes); TIMER_START(generate_edges); GenerateEdgeExpandedEdges(original_edge_data_filename, lua_state); TIMER_STOP(generate_edges); m_geometry_compressor.SerializeInternalVector(geometry_filename); SimpleLogger().Write() << "Timing statistics for edge-expanded graph:"; SimpleLogger().Write() << "Geometry compression: " << TIMER_SEC(geometry) << "s"; SimpleLogger().Write() << "Renumbering edges: " << TIMER_SEC(renumber) << "s"; SimpleLogger().Write() << "Generating nodes: " << TIMER_SEC(generate_nodes) << "s"; SimpleLogger().Write() << "Generating edges: " << TIMER_SEC(generate_edges) << "s"; }
double ProblemDescription::evaluateConstraint( const double * xi, double * h, double * H ) { if ( factory.empty() ) {return 0; } TIMER_START( "constraint" ); assert( h ); // make sure that h is not NULL prepareData( xi ); MatMap h_map( h, factory.numOutput(), 1 ); if ( !H ){ const double val = factory.evaluate( trajectory, h_map ); TIMER_STOP( "constraint" ); return val; } MatMap H_map( H, trajectory.size(), factory.numOutput() ); double magnitude = factory.evaluate(trajectory, h_map, H_map ); if( doing_covariant ){ //TODO find out if this is correct MatMap H_map2( H, trajectory.N(), trajectory.M()*factory.numOutput() ); metric.multiplyLowerInverse( H_map2 ); } TIMER_STOP( "constraint" ); return magnitude; }
void Delayms (uint32_t ms) { TIMER_STOP(); TIMER_START(ms * 1000); while (!TIMER_EXPIRED()); TIMER_STOP(); }
void irkit_http_loop() { #ifdef USE_INTERNET // long poll if (TIMER_FIRED(polling_timer)) { TIMER_STOP(polling_timer); if (TIMER_RUNNING(suspend_polling_timer)) { // suspend GET /m for a while if we have received a POST /messages request from client // client is in wifi, we can ignore our server for a while TIMER_START(polling_timer, SUSPEND_GET_MESSAGES_INTERVAL); } else { int8_t result = irkit_httpclient_get_messages(); if ( result < 0 ) { HTTPLOG_PRINTLN("!E3"); // maybe time cures GS? (no it doesn't, let's hardware reset, software reset doesn't work here) // don't software reset AVR, because that cuts off serial logging (for debug purpose only) wifi_hardware_reset(); } else { polling_cid = result; } } } if (TIMER_FIRED(suspend_polling_timer)) { TIMER_STOP(suspend_polling_timer); } #endif }
uint8_t GSwifi::checkActivity() { static uint8_t continuous_timeouts_ = 0; while ( serial_->available() && ! TIMER_FIRED(timeout_timer_) ) { parseByte( serial_->read() ); if ( gs_failure_ || (gs_ok_ && (gs_response_lines_ == RESPONSE_LINES_ENDED || gs_commandmode_ == GSCOMMANDMODE_NONE)) ) { gs_commandmode_ = GSCOMMANDMODE_NONE; continuous_timeouts_ = 0; setBusy(false); break; } } if ( busy_ && TIMER_FIRED(timeout_timer_) ) { TIMER_STOP(timeout_timer_); GSLOG_PRINTLN("!E24"); did_timeout_ = true; continuous_timeouts_ ++; setBusy(false); } // need a GS hardware reset, which we issue in setup() ASSERT( continuous_timeouts_ <= 5 ); return busy_; }
int test_sbit_cache( btimer_t* timer, FT_Face face, void* user_data ) { FTC_SBit glyph; int i, done = 0; FT_UNUSED( user_data ); if ( !sbit_cache ) { if ( FTC_SBitCache_New(cache_man, &sbit_cache) ) return 0; } TIMER_START( timer ); for ( i = 0; i < face->num_glyphs; i++ ) { if ( !FTC_SBitCache_Lookup(sbit_cache, &font_type, i, &glyph, NULL) ) done++; } TIMER_STOP( timer ); return done; }
/** * Tests inserting blob data as a stream * * @throws Exception * if an error occurs */ void BlobTest::testBlobInsert( Connection & c, bool asString ) { TIMER_START( "Populating blob table" ); pstmt.reset( conn->prepareStatement("INSERT INTO BLOBTEST(blobdata) VALUES (?)") ); if ( asString ) { sql::SQLString str; testBlobFile->readFile( const_cast<std::string&>(str.asStdString()) ); pstmt->setString( 1, str ); pstmt->execute(); } else { std::fstream & bIn= testBlobFile->getStream(); ASSERT( ! bIn.fail() ); pstmt->setBlob( 1, & bIn ); pstmt->execute(); } TIMER_STOP("Populating blob table"); pstmt->clearParameters(); doRetrieval(); }
/* save screenshot in bmp format, return true if success, or false */ bool CScreenShot::SaveBmp() { TIMER_START(); if(!OpenFile()) return false; unsigned char hdr[14 + 40]; unsigned int i = 0; #define PUT32(x) hdr[i++] = ((x)&0xFF); hdr[i++] = (((x)>>8)&0xFF); hdr[i++] = (((x)>>16)&0xFF); hdr[i++] = (((x)>>24)&0xFF); #define PUT16(x) hdr[i++] = ((x)&0xFF); hdr[i++] = (((x)>>8)&0xFF); #define PUT8(x) hdr[i++] = ((x)&0xFF); PUT8('B'); PUT8('M'); PUT32((((xres * yres) * 3 + 3) &~ 3) + 14 + 40); PUT16(0); PUT16(0); PUT32(14 + 40); PUT32(40); PUT32(xres); PUT32(yres); PUT16(1); PUT16(4*8); // bits PUT32(0); PUT32(0); PUT32(0); PUT32(0); PUT32(0); PUT32(0); #undef PUT32 #undef PUT16 #undef PUT8 fwrite(hdr, 1, i, fd); int y; for (y=yres-1; y>=0 ; y-=1) { fwrite(pixel_data+(y*xres*4),xres*4,1,fd); } fclose(fd); TIMER_STOP(filename.c_str()); return true; }
void CFrontend::sendDiseqcCommand(const struct dvb_diseqc_master_cmd *cmd, const uint32_t ms) { TIMER_START(); #if HAVE_DVB_API_VERSION >= 3 if (fop(ioctl, FE_DISEQC_SEND_MASTER_CMD, cmd) == 0) #else secCmdSequence sequence; secCommand command; sequence.miniCommand = SEC_MINI_NONE; sequence.continuousTone = currentToneMode; sequence.voltage = currentTransponder.polarization; command.type = SEC_CMDTYPE_DISEQC_RAW; command.u.diseqc.cmdtype = cmd->msg[0]; command.u.diseqc.addr = cmd->msg[1]; command.u.diseqc.cmd = cmd->msg[2]; command.u.diseqc.numParams = cmd->msg_len - 3; for (int i=0; i < (cmd->msg_len - 3); i++) command.u.diseqc.params[i] = cmd->msg[3 + i]; sequence.commands = &command; sequence.numCommands = 1; if (fop_sec(ioctl, SEC_SEND_SEQUENCE, sequence) == 0) #endif usleep(1000 * ms); TIMER_STOP(); }
void IR_state (uint8_t nextState) { switch (nextState) { case IR_IDLE: IR_TX_OFF(); IR_COMPARE_DISABLE(); // 1st interrupt when receiving ir must be falling edge IR_CAPTURE_FALL(); IR_CAPTURE_ENABLE(); IR_clear(); break; case IR_RECVING: IR_clear(); TIMER_START( IrCtrl.recv_timer, RECV_TIMEOUT ); break; case IR_RECVED: TIMER_STOP( IrCtrl.recv_timer ); irpacker_packend( &packer_state ); // disable til IRKit.cpp reports IR data to server IR_CAPTURE_DISABLE(); IR_COMPARE_DISABLE(); if (IrCtrl.len < VALID_IR_LEN_MIN) { // received, but probably noise IR_state( IR_IDLE ); return; } break; case IR_RECVED_IDLE: // holds received IR data, and ready to receive next IR_CAPTURE_FALL(); IR_CAPTURE_ENABLE(); break; case IR_READING: irpacker_unpack_start( &packer_state ); IR_CAPTURE_DISABLE(); IR_COMPARE_DISABLE(); break; case IR_WRITING: IR_CAPTURE_DISABLE(); IR_COMPARE_DISABLE(); IR_clear(); break; case IR_XMITTING: IR_CAPTURE_DISABLE(); IR_COMPARE_DISABLE(); IrCtrl.tx_index = 0; TIMER_START( IrCtrl.xmit_timer, XMIT_TIMEOUT ); break; case IR_DISABLED: IR_CAPTURE_DISABLE(); IR_COMPARE_DISABLE(); break; } IrCtrl.state = nextState; }
int test_get_cbox( btimer_t* timer, FT_Face face, void* user_data ) { FT_Glyph glyph; FT_BBox bbox; int i, done = 0; FT_UNUSED( user_data ); for ( i = 0; i < face->num_glyphs; i++ ) { if ( FT_Load_Glyph( face, i, load_flags ) ) continue; if ( FT_Get_Glyph( face->glyph, &glyph ) ) continue; TIMER_START( timer ); FT_Glyph_Get_CBox( glyph, FT_GLYPH_BBOX_PIXELS, &bbox ); TIMER_STOP( timer ); FT_Done_Glyph( glyph ); done++; } return done; }
void generate_level(Level *lvl, char *id) { LevelGeneratorFunc func = NULL; unsigned i; clock_t t; /* If 'id' is null, go with the default: */ if(!id) id = GENERATOR_LIST[0].id; /* Look for the id: */ for(i=0; GENERATOR_LIST[i].id; i++) { if(!strcmp(id, GENERATOR_LIST[i].id)) { gamelib_print("Using level generator: '%s'\n", GENERATOR_LIST[i].id); func = GENERATOR_LIST[i].gen; goto generate_level; } } /* Report what level generator we found: */ gamelib_print("Couldn't find level generator: '%s'\n", id); gamelib_print("Using default level generator: '%s'\n", GENERATOR_LIST[0].id); /* If we didn't find the id, then we select the default: */ if(!func) func = GENERATOR_LIST[0].gen; generate_level: TIMER_START(t); /* Ok, now generate the level: */ func(lvl); gamelib_print("Level generated in: "); TIMER_STOP(t); }
int test_cmap_cache( btimer_t* timer, FT_Face face, void* user_data ) { bcharset_t* charset = (bcharset_t*)user_data; int i, done = 0; FT_UNUSED( face ); if ( !cmap_cache ) { if ( FTC_CMapCache_New(cache_man, &cmap_cache) ) return 0; } TIMER_START( timer ); for ( i = 0; i < charset->size; i++ ) { if ( FTC_CMapCache_Lookup( cmap_cache, font_type.face_id, 0, charset->code[i] ) ) done++; } TIMER_STOP( timer ); return done; }
int test_get_glyph( btimer_t* timer, FT_Face face, void* user_data ) { FT_Glyph glyph; int i, done = 0; FT_UNUSED( user_data ); for ( i = 0; i < face->num_glyphs; i++ ) { if ( FT_Load_Glyph( face, i, load_flags ) ) continue; TIMER_START( timer ); if ( !FT_Get_Glyph( face->glyph, &glyph ) ) { FT_Done_Glyph( glyph ); done++; } TIMER_STOP( timer ); } return done; }
uint32_t CFrontend::getDiseqcReply(const int timeout_ms) const { struct dvb_diseqc_slave_reply reply; reply.timeout = timeout_ms; TIMER_START(); if (fop(ioctl, FE_DISEQC_RECV_SLAVE_REPLY, &reply) < 0) return 0; TIMER_STOP(); /* timeout */ if (reply.msg_len == 0) return 1; switch (reply.msg[0]) { case 0xe4: /* ok */ return 0; case 0xe5: /* invalid address or unknown command */ return 1; case 0xe6: /* parity error */ return 1; case 0xe7: /* contention flag mismatch */ return 1; default: /* unexpected reply */ return 0; } }
int main(int argc, char** argv){ int n; if (argc > 1) n = atoi(argv[1]); else n = 40; if (cilk_io_init()) { fprintf(stderr,"cilk_io_init failed\n"); exit(1); } int socketID; long j; int i; int arr[NUM_SERVERS]; int* sockIDs = initReduce(); my_timer_t t; TIMER_START(t); // Currently it only works if cilk_read/writes are within a cilk_spawn cilk_spawn distPfib(n, sockIDs, &j); TIMER_STOP(t); printf("computed distFib of %d\treturned: %lu\ttime: %4f\n", n, j, TIMER_EVAL(t)); return 0; }
int main (int argc, char **argv) { STATIC int w, h, bit_num; STATIC unsigned char byte_acc; STATIC int i; STATIC int iter = 50; STATIC double x, y; STATIC double Zr, Zi, Cr, Ci, Tr, Ti; STATIC double limit = 2.0; #ifdef COMMAND w = argc > 1 ? atoi(argv[1]) : 60; h = argc > 2 ? atoi(argv[2]) : w; #else w = h = 60; #endif PRINTF3("P4\n%d %d\n",w,h); TIMER_START(); for(y=0;y<h;++y) { for(x=0;x<w;++x) { Zr = Zi = Tr = Ti = 0.0; Cr = (2.0*x/w - 1.5); Ci=(2.0*y/h - 1.0); for (i=0;i<iter && (Tr+Ti <= limit*limit);++i) { Zi = 2.0*Zr*Zi + Ci; Zr = Tr - Ti + Cr; Tr = Zr * Zr; Ti = Zi * Zi; } byte_acc <<= 1; if(Tr+Ti <= limit*limit) byte_acc |= 0x01; ++bit_num; if(bit_num == 8) { PUTC(byte_acc,stdout); byte_acc = 0; bit_num = 0; } else if(x == w-1) { byte_acc <<= (8-w%8); PUTC(byte_acc,stdout); byte_acc = 0; bit_num = 0; } } } TIMER_STOP(); }
void perform_sort(void) { TIMER_START(); qsort(numbers, NUM, sizeof(int), ascending_order); TIMER_STOP(); }
/* save screenshot in jpg format, return true if success, or false */ bool CScreenShot::SaveJpg() { int quality = 90; TIMER_START(); if(!OpenFile()) return false; for (int y = 0; y < yres; y++) { int xres1 = y*xres*3; int xres2 = xres1+2; for (int x = 0; x < xres; x++) { int x2 = x*3; memcpy(pixel_data + x2 + xres1, pixel_data + x*4 + y*xres*4, 3); SWAP(pixel_data[x2 + xres1], pixel_data[x2 + xres2]); } } struct jpeg_compress_struct cinfo; struct my_error_mgr jerr; JSAMPROW row_pointer[1]; unsigned int row_stride; cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; if (setjmp(jerr.setjmp_buffer)) { printf("CScreenShot::SaveJpg: %s save error\n", filename.c_str()); jpeg_destroy_compress(&cinfo); fclose(fd); return false; } jpeg_create_compress(&cinfo); jpeg_stdio_dest(&cinfo, fd); cinfo.image_width = xres; cinfo.image_height = yres; cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; cinfo.dct_method = JDCT_IFAST; jpeg_set_defaults(&cinfo); jpeg_set_quality(&cinfo, quality, TRUE); jpeg_start_compress(&cinfo, TRUE); row_stride = xres * 3; while (cinfo.next_scanline < cinfo.image_height) { row_pointer[0] = & pixel_data[cinfo.next_scanline * row_stride]; jpeg_write_scanlines(&cinfo, row_pointer, 1); } jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); fclose(fd); TIMER_STOP(filename.c_str()); return true; }
// run with -p 20 -l 5000 int main(int argc, char *argv[]) { struct item items[MAX_ITEMS]; /* array of items */ int n, capacity, sol, benchmark, help; char filename[100]; my_timer_t t; /* standard benchmark options */ strcpy(filename, "knapsack-example3.input"); #ifdef CILK_BLOCK cilk_io_init(); #endif get_options(argc, argv, specifiers, opt_types, &prob, &length, filename, &benchmark, &help); if (help) return usage(); if (benchmark) { switch (benchmark) { case 1: /* short benchmark options -- a little work */ strcpy(filename, "knapsack-example1.input"); break; case 2: /* standard benchmark options */ strcpy(filename, "knapsack-example2.input"); break; case 3: /* long benchmark options -- a lot of work */ strcpy(filename, "knapsack-example3.input"); break; } } if (read_input(filename, items, &capacity, &n)) return 1; /* Timing. "Start" timers */ cilk_sync; printf("prob = %lu\tlength=%lu\tn = %lu\n", prob, length, n); TIMER_RESET(t); TIMER_START(t); sol = cilk_spawn knapsack(items, capacity, n, 0); cilk_sync; TIMER_STOP(t); #ifdef CILK_BLOCK cilk_io_teardown(); #endif printf("\nCilk Example: knapsack\n"); printf("options: problem-file = %s\n\n", filename); printf("Best value is %d\n\n", sol); printf("Running time = %4f s\n", TIMER_EVAL(t)); return 0; }
void GSwifi::loop() { TIMER_STOP( timeout_timer_ ); checkActivity(); for (uint8_t i=0; i<16; i++) { if (! cidIsRequest(i) && TIMER_FIRED(timers_[i])) { TIMER_STOP(timers_[i]); GSLOG_PRINT("!E4 "); GSLOG_PRINTLN(i); // request (from us) timeout means GS is in trouble, // and it's easy to just rescue ourselves to reset wifi_hardware_reset(); return; } } }
void IR_timer (void) { if (IrCtrl.state == IR_RECVING) { TIMER_TICK( IrCtrl.recv_timer ); if ( TIMER_FIRED( IrCtrl.recv_timer ) ) { TIMER_STOP( IrCtrl.recv_timer ); IR_state( IR_RECVED ); } } if (IrCtrl.state == IR_XMITTING) { TIMER_TICK( IrCtrl.xmit_timer ); if ( TIMER_FIRED( IrCtrl.xmit_timer ) ) { TIMER_STOP( IrCtrl.xmit_timer ); IR_state( IR_IDLE ); } } }
void UndoManager::CalculateSpaceUsage() { TIMER_START( "CalculateSpaceUsage", space_calc ); TrackListOfKindIterator iter(Track::Wave); space.Clear(); space.Add(0, stack.GetCount()); Set s1, s2; Set *prev = &s1; Set *cur = &s2; for (size_t i = 0, cnt = stack.GetCount(); i < cnt; i++) { // Swap map pointers std::swap(cur, prev); // And clean out the NEW current map cur->clear(); // Scan all tracks at current level WaveTrack *wt = (WaveTrack *) iter.First(stack[i]->tracks); while (wt) { // Scan all clips within current track WaveClipList::compatibility_iterator it = wt->GetClipIterator(); while (it) { // Scan all blockfiles within current clip BlockArray *blocks = it->GetData()->GetSequenceBlockArray(); for (size_t b = 0, cnt = blocks->size(); b < cnt; b++) { BlockFile *file = (*blocks)[b].f; // Accumulate space used by the file if the file didn't exist // in the previous level if (prev->count(file) == 0 && cur->count(file) == 0) { space[i] += file->GetSpaceUsage().GetValue(); } // Add file to current set cur->insert(file); } it = it->GetNext(); } wt = (WaveTrack *) iter.Next(); } } TIMER_STOP( space_calc ); }
void CFrontend::secResetOverload(void) { TIMER_START(); #if HAVE_DVB_API_VERSION >= 3 fop(ioctl, FE_DISEQC_RESET_OVERLOAD); #else printf("CFrontend::secResetOverload() not implemented in old API\n"); #endif TIMER_STOP(); }
void CFrontend::secSetVoltage(const fe_sec_voltage_t voltage, const uint32_t ms) { TIMER_START(); if (fop_sec(ioctl, FE_SET_VOLTAGE, voltage) == 0) { currentTransponder.polarization = voltage; usleep(1000 * ms); } TIMER_STOP(); }
void CFrontend::secSetTone(const fe_sec_tone_mode_t toneMode, const uint32_t ms) { TIMER_START(); if (fop_sec(ioctl, FE_SET_TONE, toneMode) == 0) { currentToneMode = toneMode; usleep(1000 * ms); } TIMER_STOP(); }
/* save screenshot in png format, return true if success, or false */ bool CScreenShot::SavePng() { png_bytep *row_pointers; png_structp png_ptr; png_infop info_ptr; TIMER_START(); if(!OpenFile()) return false; row_pointers = (png_bytep *) malloc(sizeof(png_bytep) * yres); if (!row_pointers) { printf("CScreenShot::SavePng: malloc error\n"); fclose(fd); return false; } png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, (png_error_ptr)NULL, (png_error_ptr)NULL); info_ptr = png_create_info_struct(png_ptr); if (setjmp(png_jmpbuf(png_ptr))) { printf("CScreenShot::SavePng: %s save error\n", filename.c_str()); png_destroy_write_struct(&png_ptr, &info_ptr); free(row_pointers); fclose(fd); return false; } png_init_io(png_ptr, fd); int y; for (y=0; y<yres; y++) { row_pointers[y] = pixel_data + (y*xres*4); } png_set_IHDR(png_ptr, info_ptr, xres, yres, 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); //png_set_filter (png_ptr, 0, PNG_FILTER_NONE); png_set_compression_level(png_ptr, Z_BEST_SPEED); png_set_bgr(png_ptr); #ifdef BOXMODEL_APOLLO png_set_invert_alpha(png_ptr); #endif png_write_info(png_ptr, info_ptr); png_write_image(png_ptr, row_pointers); png_write_end(png_ptr, info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr); free(row_pointers); fclose(fd); TIMER_STOP(filename.c_str()); return true; }
// does recurse int8_t GSwifi::close (int8_t cid) { char *cmd = PB("AT+NCLOSE=0", 1); cmd[ 10 ] = i2x(cid); TIMER_STOP( timers_[cid] ); command(cmd, GSCOMMANDMODE_NORMAL); if (did_timeout_) { return -1; } return 0; }
void CBouquetManager::loadBouquets(bool ignoreBouquetFile) { TIMER_START(); clearAll(); if (ignoreBouquetFile == false) { parseBouquetsXml(BOUQUETS_XML, false); sortBouquets(); } parseBouquetsXml(UBOUQUETS_XML, true); renumServices(); TIMER_STOP("[zapit] bouquet loading took"); }
void GSwifi::clear () { joined_ = false; listening_ = false; limited_ap_ = false; resetResponse(GSCOMMANDMODE_NONE); gs_mode_ = GSMODE_COMMAND; ring_clear(_buf_cmd); memset(ipaddr_, 0, sizeof(ipaddr_)); for (uint8_t i=0; i<16; i++) { TIMER_STOP( timers_[i] ); } }