// Copyright (c) 2008 Ole Weidner // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include "saga-file.hpp" #include #include #include #if BOOST_VERSION >= 104000 #include #include #include #include #include #endif #define ITERATIONS 100 /////////////////////////////////////////////////////////////////////////////// // void run_benchmarks (std::string smallFile, std::string largeFile, std::string targetDir, int copyIterations) { #if BOOST_VERSION >= 104000 using namespace boost::accumulators; using namespace saga::attributes; using namespace saga::adaptors::utils; accumulator_set > > acc_sync; accumulator_set > > acc_async; time_t start, current, diff; high_resolution_timer t; SAGA_GUARDED_EXEC ( saga::filesystem::file sf(smallFile); saga::filesystem::file lf(largeFile); // unused at the moment // unsigned int sf_size = sf.get_size(); // unsigned int lf_size = lf.get_size(); std::string it_str = boost::lexical_cast(copyIterations); t.restart(); std::cout << "\n* Create a saga::session object: " << std::flush; saga::session s; std::cout << t.elapsed() << " sec. (1st time)" << std::endl; t.restart(); std::cout << " Create a saga::session object: " << std::flush; for(int i=0; i < ITERATIONS; ++i) { saga::session s; } std::cout << t.elapsed()/ITERATIONS << " sec. (avg)\n" << std::endl; t.restart(); std::cout << "* Create a saga::url object: " << std::flush; saga::url u(smallFile); std::cout << t.elapsed() << " sec. (1st time)" << std::endl; t.restart(); std::cout << " Create a saga::url object: " << std::flush; for(int i=0; i < ITERATIONS; ++i) { saga::url u(smallFile); } std::cout << t.elapsed()/ITERATIONS << " sec. (avg)\n" << std::endl; t.restart(); std::cout << "* Create a saga::file object: " << std::flush; saga::filesystem::file f(smallFile); std::cout << t.elapsed() << " sec. (1st time)" << std::endl; t.restart(); std::cout << " Create a saga::file object: " << std::flush; for(int i=0; i < ITERATIONS; ++i) { saga::filesystem::file f(smallFile); } std::cout << t.elapsed()/ITERATIONS << " sec. (avg)\n" << std::endl; for(int i=0; i < ITERATIONS; ++i) { saga::filesystem::file f1(smallFile); saga::filesystem::file f2(smallFile); saga::filesystem::file f3(smallFile); saga::filesystem::file f4(smallFile); ///////////////////////// // SYNC SYNC SYNC SYNC // ///////////////////////// // time(&start); // std::cout << "\n* Copying file to five four synchronously : " << std::flush; // f1.copy("gsiftp://qb1.loni.org:2811//tmp/", saga::filesystem::Overwrite); std::cout << "f1 " << std::flush; //f2.copy("gsiftp://gridftp.ranger.tacc.teragrid.org:2811/", saga::filesystem::Overwrite); std::cout << "f2 " << std::flush; f3.copy("gsiftp://gridftp.bigred.iu.teragrid.org:2811//tmp/", saga::filesystem::Overwrite); std::cout << "f3 " << std::flush; f4.copy("gsiftp://tg-gridftp.lonestar.tacc.teragrid.org:2811//tmp/", saga::filesystem::Overwrite); std::cout << "f4 " << std::flush; // time(¤t); diff = difftime(current, start); std::cout << "[" << diff << " sec.]" << std::endl; acc_sync(diff); // ///////////////////////// ///////////////////////////// // ASYNC ASYNC ASYNC ASYNC // ///////////////////////////// // time(&start); // std::cout << "\n* Copying file to five four asynchronously : " << std::flush; // saga::task_container tc; saga::task t1 = f1.copy("gsiftp://qb1.loni.org:2811//tmp/", saga::filesystem::Overwrite); tc.add_task(t1); //saga::task t2 = f2.copy("gsiftp://gridftp.ranger.tacc.teragrid.org:2811//tmp/", saga::filesystem::Overwrite); //tc.add_task(t2); saga::task t3 = f3.copy("gsiftp://gridftp.bigred.iu.teragrid.org:2811//tmp/", saga::filesystem::Overwrite); tc.add_task(t3); saga::task t4 = f4.copy("gsiftp://tg-gridftp.lonestar.tacc.teragrid.org:2811//tmp/", saga::filesystem::Overwrite); tc.add_task(t4); // tc.wait(); // time(¤t); diff = difftime(current, start); std::cout << "[" << diff << " sec.]" << std::endl; acc_async(diff); // ///////////////////////////// } std::cout << "\n* SYNC AVG: " << mean(acc_sync) << " ERROR: " << error_of(acc_sync) << std::endl; std::cout << "* ASYNC AVG: " << mean(acc_async) << " ERROR: " << error_of(acc_async) << std::endl << std::endl; /*t.restart(); std::cout << "\n* Copy small file (" << sf_size << " bytes) to " << targetDir << ": " << std::flush; sf.copy(targetDir, saga::filesystem::Overwrite); std::cout << t.elapsed() << " sec." << std::endl; time(&start); std::cout << " Copy " << it_str << " small files to " << targetDir << ": " << std::flush; for(int i=0; i < copyIterations; ++i) { sf.copy(targetDir+"/saga_file_benchmark_sync_copy_"+boost::lexical_cast(i), saga::filesystem::Overwrite); } time(¤t); diff = difftime(current, start); std::cout << diff << " sec. \n" << std::endl; sf.close(); sf = saga::filesystem::file(smallFile); time(&start); std::cout << "* Copy big file (" << lf_size << " bytes) to " << targetDir << ": " << std::flush; lf.copy(targetDir, saga::filesystem::Overwrite); time(¤t); diff = difftime(current, start); std::cout << diff << " sec.\n" << std::endl; //// TESTS USING THE ASYNC INTERFACE AND TASK CONTAINER // t.restart(); std::cout << "* ASYNC copy small file (" << sf_size << " bytes) to " << targetDir << ": " << std::flush; saga::task st = sf.copy (targetDir, saga::filesystem::Overwrite); st.wait(); std::cout << t.elapsed() << " sec." << std::endl; saga::task_container tc; time(&start); std::cout << " ASYNC copy " << it_str << " small files to: " << std::flush; for(int i=0; i < copyIterations; ++i) { saga::task st = sf.copy (targetDir+"/saga_file_benchmark_async_copy_"+boost::lexical_cast(i), saga::filesystem::Overwrite); tc.add_task(st); } tc.wait (); time(¤t); diff = difftime(current, start); std::cout << diff << " sec.\n" << std::endl;*/ ) #else std::cout << "run benchmarks is not available on this platform (Boost V1.36 required)" << std::endl; #endif }