// bench memory against number of facets in the tree // the tree is reconstructed each timer in the mesh // refinement loop void Scene::bench_memory() { if(m_pPolyhedron == NULL) { std::cout << "Load polyhedron first." << std::endl; return; } std::cout << std::endl << "Benchmark memory" << std::endl; std::cout << "#Facets, Bytes, Mbytes, Bytes/primitive" << std::endl; while(m_pPolyhedron->size_of_facets() < 2000000) { // refines mesh at increasing speed Refiner<Kernel,Polyhedron> refiner(m_pPolyhedron); std::size_t digits = nb_digits(m_pPolyhedron->size_of_facets()); unsigned int nb_splits = static_cast<unsigned int>(0.2 * std::pow(10.0,(double)digits - 1.0)); refiner.run_nb_splits(nb_splits); // constructs tree and measure memory before then after typedef CGAL::Memory_sizer::size_type size_type; size_type before = CGAL::Memory_sizer().virtual_size(); Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); // tree.accelerate_distance_queries(); // 150 vs 61 bytes per primitive! size_type after = CGAL::Memory_sizer().virtual_size(); size_type bytes = after - before; // in Bytes double mbytes = (double)bytes / (double)1048576; // in MBytes double bpp = (double)bytes / (double)m_pPolyhedron->size_of_facets(); std::cout << m_pPolyhedron->size_of_facets() << ", " << bytes << ", " << mbytes << ", " << bpp << std::endl; } }
void Scene::bench_distances_vs_nbt() { if(m_pPolyhedron == NULL) { std::cout << "Load polyhedron first." << std::endl; return; } std::cout << std::endl << "Benchmark distances against #triangles" << std::endl; std::cout << std::endl << "for random point queries and closest_point()" << std::endl; std::cout << "#Facets, #queries/s" << std::endl; // generates 10K random point queries const int nb_queries = 10000; std::vector<Point> queries; srand(0); for(int i=0;i<nb_queries;i++) queries.push_back(random_point(m_bbox)); while(m_pPolyhedron->size_of_facets() < 1000000) { // refines mesh at increasing speed Refiner<Kernel,Polyhedron> refiner(m_pPolyhedron); std::size_t digits = nb_digits(m_pPolyhedron->size_of_facets()); unsigned int nb_splits = static_cast<unsigned int>(0.2 * std::pow(10.0,(double)digits - 1.0)); refiner.run_nb_splits(nb_splits); // constructs tree (out of timing) Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); tree.accelerate_distance_queries(); // calls queries CGAL::Timer timer; timer.start(); for(int i=0;i<nb_queries;i++) tree.closest_point(queries[i]); double duration = timer.time(); int speed = (int)((double)nb_queries / (double)duration); std::cout << m_pPolyhedron->size_of_facets() << ", " << speed << std::endl; } }
void Scene::bench_construction() { if(m_pPolyhedron == NULL) { std::cout << "Load polyhedron first." << std::endl; return; } std::cout << std::endl << "Benchmark construction" << std::endl; std::cout << "#Facets alone (s) with KD-tree (s)" << std::endl; while(m_pPolyhedron->size_of_facets() < 1000000) { // refines mesh at increasing speed Refiner<Kernel,Polyhedron> refiner(m_pPolyhedron); std::size_t digits = nb_digits(m_pPolyhedron->size_of_facets()); unsigned int nb_splits = static_cast<unsigned int>(0.2 * std::pow(10.0,(double)digits - 1.0)); refiner.run_nb_splits(nb_splits); // constructs tree CGAL::Timer time1; time1.start(); Facet_tree tree1(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); double duration_construction_alone = time1.time(); CGAL::Timer time2; time2.start(); Facet_tree tree2(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); tree2.accelerate_distance_queries(); double duration_construction_and_kdtree = time2.time(); std::cout << m_pPolyhedron->size_of_facets() << "\t" << duration_construction_alone << "\t" << duration_construction_and_kdtree << std::endl; } }
void Language_C::_write_parse_func( std::ostream &os ) { StreamSepMaker<std::ostream> on( os ); int nb_spaces = 5; String sp( nb_spaces, ' ' ); on.beg = sp.c_str(); // parse os << "int parse" << f_suf << "( " << cp->struct_name << " *sipe_data, SIPE_CHARP data, SIPE_CHARP end ) {\n"; if ( nb_marks ) on << "SIPE_CHARP beg_data = data;\n"; on << "if ( sipe_data->_inp_cont )"; on << " goto *sipe_data->_inp_cont;"; on << ""; on << "#define INCR( N ) if ( ++data >= end ) goto p_##N; c_##N:"; on << ""; // blocks for( int i = 0; i < block_seq.size(); ++i ) { Block *b = block_seq[ i ]; if ( not b->write ) continue; // if ( b->label >= 0 ) { os << "l_" << b->label << ":"; on.first_beg = on.beg + std::min( nb_spaces, 3 + nb_digits( b->label ) ); } // if ( b->state ) { // action if ( b->state->action ) b->state->action->write_code( on, this ); // end ? if ( b->state->end ) { on << "sipe_data->_inp_cont = &&l_" << b->label << ";"; on << "return " << b->state->end << ";"; } // if ( b->state->set_mark ) { on << "sipe_data->_mark[ " << marks[ b->state ] << " ] = data;"; on << "sipe_data->_mark_data[ " << marks[ b->state ] << " ].clear();"; } // if ( b->state->use_mark ) { int nm = marks[ b->state->use_mark ]; on << "if ( sipe_data->_mark[ " << nm << " ] ) {"; on << " data = sipe_data->_mark[ " << nm << " ];"; on << "} else {"; // on << " std::cout << '-' << sipe_data->_mark_data[ " << nm << " ] << '-' << std::endl;"; on << " sipe_data->_inp_cont = &&cnt_mark_" << b << ";"; on << " SIPE_CHARP beg = (SIPE_CHARP)sipe_data->_mark_data[ " << nm << " ].data();"; on << " int res = parse( sipe_data, beg, beg + sipe_data->_mark_data[ " << nm << " ].size() );"; on << " if ( res )"; on << " return res;"; on << " data = beg_data;"; on << " goto *sipe_data->_inp_cont;"; on << "}"; os << "cnt_mark_" << b << ":\n"; } // if ( b->state->rem_mark ) { } // if ( b->state->incc ) { on << "INCR( " << cnt.size() << " )"; Cnt c; c.block = b; c.label = b->label; cnt << c; } } // if ( b->ko ) { if ( b->t_ok ) { // if ( cond ) goto ok; String cond = b->cond.ok_cpp( "*data", &b->not_in ); on << "if ( " << cond << " ) goto l_" << b->ok->label << ";"; } else { // if ( not cond ) goto ko; String cond = b->cond.ko_cpp( "*data", &b->not_in ); on << "if ( " << cond << " ) goto l_" << b->ko->label << ";"; } } // if ( b->write_goto ) on << "goto l_" << b->write_goto->label << ";"; } // cnt for( int i = 0; i < cnt.size(); ++i ) { os << "p_" << i << ":"; on.first_beg = on.beg + std::min( nb_spaces, 3 + nb_digits( i ) ); if ( const State *m = cnt[ i ].block->mark ) { // on << "std::cout << *sipe_data->_mark[ " << marks[ m ] << " ] << std::endl;"; on << "sipe_data->_mark_data[ " << marks[ m ] << " ].append( sipe_data->_mark[ " << marks[ m ] << " ] ? sipe_data->_mark[ " << marks[ m ] << " ] : beg_data, data );"; on << "sipe_data->_mark[ " << marks[ m ] << " ] = 0;"; } on << "sipe_data->_inp_cont = &&c_" << i << "; return 0;"; } os << "}\n"; }
static int nb_digits( int val ) { if ( val < 0 ) return 1 + nb_digits( -val ); if ( val < 10 ) return 1; return 1 + nb_digits( val / 10 ); }