From: Foster B. <fos...@us...> - 2006-02-03 18:21:08
|
Update of /cvsroot/adobe-source/adobe-source/adobe/test/xstr_bench In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1031/adobe/test/xstr_bench Modified Files: main.cpp Log Message: asl 1.0.13 Index: main.cpp =================================================================== RCS file: /cvsroot/adobe-source/adobe-source/adobe/test/xstr_bench/main.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** main.cpp 6 Jan 2006 18:35:27 -0000 1.2 --- main.cpp 3 Feb 2006 18:20:49 -0000 1.3 *************** *** 1,6 **** /* ! Copyright 2005-2006 Adobe Systems Incorporated ! Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt ! or a copy at http://opensource.adobe.com/licenses.html) */ --- 1,6 ---- /* ! Copyright 2005-2006 Adobe Systems Incorporated ! Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt ! or a copy at http://opensource.adobe.com/licenses.html) */ *************** *** 78,97 **** std::string generate_lorem(int min, int max, bool nopunct = false) { ! std::string result; ! std::size_t this_count(std::rand() % (max - min + 1) + min); ! for (std::size_t i(0); i < this_count; ++i) ! { ! if (i != 0) result << " "; ! result << lorem_g[std::rand() % lorem_size_g]; ! } ! if (nopunct) ! for (std::string::iterator first(result.begin()), last(result.end()); first != last; ++first) ! if (!std::isalpha(*first)) ! *first = '_'; ! return result; } --- 78,97 ---- std::string generate_lorem(int min, int max, bool nopunct = false) { ! std::string result; ! std::size_t this_count(std::rand() % (max - min + 1) + min); ! for (std::size_t i(0); i < this_count; ++i) ! { ! if (i != 0) result << " "; ! result << lorem_g[std::rand() % lorem_size_g]; ! } ! if (nopunct) ! for (std::string::iterator first(result.begin()), last(result.end()); first != last; ++first) ! if (!std::isalpha(*first)) ! *first = '_'; ! return result; } *************** *** 100,122 **** void generate_file(int argc, char** argv) { ! std::size_t test_string_count(15000); ! if (argc > 1) ! test_string_count = std::atoi(argv[1]); ! boost::filesystem::path boost_path(glossary_name_g, boost::filesystem::native); ! std::cout << "Generating xstring file with " << test_string_count << " strings..." << std::endl; ! boost::filesystem::ofstream out(boost_path); ! adobe::timer_t gen_timer; ! for (std::size_t i(0); i < test_string_count; ++i) ! out << "<xstr id='" << generate_lorem(2, 5, true) << "-" << i << "'>" << generate_lorem(1, 30) << "</xstr>" << std::endl; ! gen_timer.report("Generation"); ! out.close(); } --- 100,122 ---- void generate_file(int argc, char** argv) { ! std::size_t test_string_count(15000); ! if (argc > 1) ! test_string_count = std::atoi(argv[1]); ! boost::filesystem::path boost_path(glossary_name_g, boost::filesystem::native); ! std::cout << "Generating xstring file with " << test_string_count << " strings..." << std::endl; ! boost::filesystem::ofstream out(boost_path); ! adobe::timer_t gen_timer; ! for (std::size_t i(0); i < test_string_count; ++i) ! out << "<xstr id='" << generate_lorem(2, 5, true) << "-" << i << "'>" << generate_lorem(1, 30) << "</xstr>" << std::endl; ! gen_timer.report("Generation"); ! out.close(); } *************** *** 125,140 **** std::size_t do_test(adobe::file_slurp<char>& slurp, adobe::timer_t& timer) { ! slurp.reslurp(); ! timer.reset(); ! adobe::xstring_context_t context( slurp.begin(), slurp.end(), ! adobe::line_position_t(glossary_name_g)); ! timer.accrue(); ! slurp.release(); ! return adobe::implementation::top_frame().glossary_m.size(); } --- 125,140 ---- std::size_t do_test(adobe::file_slurp<char>& slurp, adobe::timer_t& timer) { ! slurp.reslurp(); ! timer.reset(); ! adobe::xstring_context_t context( slurp.begin(), slurp.end(), ! adobe::line_position_t(glossary_name_g)); ! timer.accrue(); ! slurp.release(); ! return adobe::implementation::top_frame().glossary_m.size(); } *************** *** 147,196 **** int main(int argc, char** argv) { ! int result(0); ! std::srand(std::time(NULL)); ! try ! { ! boost::filesystem::path boost_path(glossary_name_g, boost::filesystem::native); ! if (!boost::filesystem::exists(boost_path)) ! generate_file(argc, argv); ! adobe::file_slurp<char> slurp(boost_path); ! adobe::timer_t timer; ! std::size_t repeat_count(20); ! std::size_t count(0); ! std::cout << "Repeating test " << repeat_count << " times..." << std::endl; ! for (std::size_t i(0); i < repeat_count;) ! { ! count = std::max(count, do_test(slurp, timer)); ! std::cerr << ++i << " "; ! } ! std::cout << std::endl; ! double avg(timer.accrued_average()); ! std::cout << "Average time taken: " << avg << " milliseconds (" << avg / 1e3 << " sec)" << std::endl; ! std::cout << "Found " << count << " parsed elements in glossary." << std::endl; ! } ! catch (const std::exception& doh) ! { ! std::cerr << "Exception: " << doh.what() << "\n"; ! result = 1; ! } ! catch (...) ! { ! std::cerr << "Unknown Exception\n"; ! result = 1; ! } ! return result; } --- 147,196 ---- int main(int argc, char** argv) { ! int result(0); ! std::srand(std::time(NULL)); ! try ! { ! boost::filesystem::path boost_path(glossary_name_g, boost::filesystem::native); ! if (!boost::filesystem::exists(boost_path)) ! generate_file(argc, argv); ! adobe::file_slurp<char> slurp(boost_path); ! adobe::timer_t timer; ! std::size_t repeat_count(20); ! std::size_t count(0); ! std::cout << "Repeating test " << repeat_count << " times..." << std::endl; ! for (std::size_t i(0); i < repeat_count;) ! { ! count = std::max(count, do_test(slurp, timer)); ! std::cerr << ++i << " "; ! } ! std::cout << std::endl; ! double avg(timer.accrued_average()); ! std::cout << "Average time taken: " << avg << " milliseconds (" << avg / 1e3 << " sec)" << std::endl; ! std::cout << "Found " << count << " parsed elements in glossary." << std::endl; ! } ! catch (const std::exception& doh) ! { ! std::cerr << "Exception: " << doh.what() << "\n"; ! result = 1; ! } ! catch (...) ! { ! std::cerr << "Unknown Exception\n"; ! result = 1; ! } ! return result; } |