int main(int argc, char const **argv) { init_env(argc, argv); high_resolution_clock::time_point s; pthread_t workers[num_thread]; pthread_mutex_init(&queuing, NULL); pthread_cond_init(&iter_fin, NULL); pthread_cond_init(&processing, NULL); for (int i = 0; i < num_thread; ++i) pthread_create(&workers[i], NULL, worker, NULL); Gm = G * mass; for (int i = 0; i < iters; ++i) { build_tree(root); s = high_resolution_clock::now(); pthread_mutex_lock(&queuing); queuing_jobs = num_body, num_done = 0; pthread_cond_broadcast(&processing); pthread_cond_wait(&iter_fin, &queuing); pthread_mutex_unlock(&queuing); Body* t = new_bodies; new_bodies = bodies; bodies = t; total_time += timeit(s); } finsish = true; pthread_mutex_lock(&queuing); pthread_cond_broadcast(&processing); pthread_mutex_unlock(&queuing); for (int j = 0; j < num_thread; ++j) pthread_join(workers[j], NULL); INFO("- compute: " << total_time.count() / 1000 << " us"); INFO("- build tree: " << build_time.count() / 1000 << " us"); INFO("- i/o: " << io_time.count() / 1000 << " us"); return 0; }
void square_am_signal(float time, float frequency) { using namespace std::chrono ; std::cout << "Playing / " << time << " seconds / " << frequency << " Hz\n" ; seconds const sec{1} ; nanoseconds const nsec{ sec } ; using rep = nanoseconds::rep ; auto nsec_per_sec = nsec.count() ; nanoseconds const period( static_cast<rep>( nsec_per_sec / frequency) ) ; auto start = high_resolution_clock::now() ; auto const end = start + nanoseconds( static_cast<rep>(time * nsec_per_sec) ) ; while (high_resolution_clock::now() < end) { mid = start + period / 2 ; reset = start + period ; cv.notify_all() ; std::this_thread::sleep_until( reset ) ; start = reset; } }
void display_clock_resolution(std::string const & clock_name, ::clockid_t clock) { ::timespec t; if(::clock_getres(clock, &t)) throw exception(UNIVERSALIS__COMPILER__LOCATION__NO_CLASS); using namespace stdlib::chrono; nanoseconds const ns(seconds(t.tv_sec) + nanoseconds(t.tv_nsec)); std::ostringstream s; s << "clock: " << clock_name << ", resolution: " << ns.count() * 1e-9 << 's'; BOOST_MESSAGE(s.str()); }
std::string mir::logging::input_timestamp(nanoseconds when) { // Input events use CLOCK_MONOTONIC, and so we must... duration<double, std::milli> const age = steady_clock::now().time_since_epoch() - when; char str[64]; snprintf(str, sizeof str, "%lld (%.6fms ago)", static_cast<long long>(when.count()),age.count()); return std::string(str); }
int main(int argc, char const **argv) { init_env(argc, argv); omp_set_num_threads(num_thread); high_resolution_clock::time_point s; Gmm = G * mass * mass; for (int i = 0; i < iters; ++i) { if (gui) draw_points(0); s = high_resolution_clock::now(); #pragma omp parallel for schedule(dynamic, 50) for (int j = 0; j < num_body; ++j) move_nth_body(j); Body* t = new_bodies; new_bodies = bodies; bodies = t; total_time += timeit(s); } INFO("Run in " << total_time.count() / 1000 << " us"); return 0; }
void updateModifiedTime( const std::string& path, bool forward = true, nanoseconds timeDiffNano = seconds(10)) { struct stat currentFileStat; std::array<struct timespec, 2> newTimes; if (stat(path.c_str(), ¤tFileStat) < 0) { throw std::runtime_error("Failed to stat file: " + path); } #ifdef _WIN32 throw std::runtime_error("don't know how to set mtime on win32"); #elif defined(__APPLE__) || defined(__FreeBSD__) \ || (defined(__NetBSD__) && (__NetBSD_Version__ < 6099000000)) newTimes[0] = currentFileStat.st_atimespec; newTimes[1] = currentFileStat.st_mtimespec; #else newTimes[0] = currentFileStat.st_atim; newTimes[1] = currentFileStat.st_mtim; #endif auto secVal = duration_cast<seconds>(timeDiffNano).count(); auto nsecVal = timeDiffNano.count(); if (forward) { newTimes[1].tv_sec += secVal; newTimes[1].tv_nsec += nsecVal; } else { newTimes[1].tv_sec -= secVal; newTimes[1].tv_nsec -= nsecVal; } // 0 <= tv_nsec < 1e9 newTimes[1].tv_nsec %= (long)1e9; if (newTimes[1].tv_nsec < 0) { newTimes[1].tv_nsec *= -1; } if (utimensat(AT_FDCWD, path.c_str(), newTimes.data(), 0) < 0) { throw std::runtime_error("Failed to set time for file: " + path); } }
uint8_t membus_t::read(const uint16_t addr) { /*if(addr == 0xFF00){ std::cout << "P1 (Joypad) read: " << std::hex << (int)rom[0xFF00] << std::endl; }*/ if(addr == 0xFF01){ std::cout << "SB (Serial Bus) read unhandled" << std::endl; } if(addr == 0xFF02){ std::cout << "SC (Serial Control) read unhandled" << std::endl; } if(addr == 0xFF04){ std::cout << "DIV read unhandled" << std::endl; } if(addr == 0xFF05){ std::cout << "TIMA read unhandled" << std::endl; } if(addr == 0xFF06){ std::cout << "TMA read unhandled " << std::endl; } if(addr == 0xFF07){ std::cout << "TAC read unhandled " << std::endl; } if(addr == 0xFF24){ std::cout << "Sound channel control read unhandled " << std::endl; } if(addr == 0xFF25){ std::cout << "Sound channel selection read unhandled " << std::endl; } if(addr == 0xFF26){ std::cout << "Sound hardware control read unhandled " << std::endl; } if(addr == 0xFF41){ std::cout << "STAT read unhandled" << std::endl; } if(addr == 0xFF4A){ std::cout << "Read from WY register, unhandled" << std::endl; } if(addr == 0xFF4B){ std::cout << "Read from WX register, unhandled" << std::endl; } // Read the LY register, we calculate what would be in there (goes from 0x00 to 0x99 at 57Hz) if(addr == 0xFF44){ static const bool increment_per_read = false; uint8_t result = 0xA0; if(!increment_per_read){ using namespace boost::chrono; typedef high_resolution_clock clock; nanoseconds const step = (nanoseconds(seconds(1))/57); assert(step.count() > 0); nanoseconds const now_duration = clock::now().time_since_epoch(); nanoseconds const part = now_duration % step; double const normalized = normalize(0., double(step.count()), double(part.count())); double const denormalized = denormalize(0., 152., normalized); result = std::floor(denormalized); //std::cout << now_duration.count() << " " << part.count() << " -> " << int(result) << std::endl; } else { result = rom[0xFF44] = (rom[0xFF44] + 1) % 0xA0; //std::cout << int(result) << std::endl; } if(result == 0x90){ // If LY == 0x90, or IF *get_pointer(0xFFFE) |= FLAG_I_VBLANK; } assert(result <= 0x99); return result; } if(bootrom_enabled && addr < 0x100) { return bootrom[addr]; } /*if(addr >= 0x4000 && *cart_mode == 0x01) { if(rom_bank == 0x00) return rom[0x2000 + addr]; return rom[rom_bank * 0x2000 + addr]; }*/ return rom[addr]; }
void g(nanoseconds d, boost::intmax_t res) { // d.count() == 3000 when passed microseconds(3) std::cout << d.count() << " " <<res << std::endl; BOOST_ASSERT(d.count()==res); }