Skip to content

Instantly share code, notes, and snippets.

@stuartcampbell
Created April 5, 2018 01:03
Show Gist options
  • Save stuartcampbell/7e57ef7d554913d9ec0ce332b54d3e08 to your computer and use it in GitHub Desktop.
Save stuartcampbell/7e57ef7d554913d9ec0ce332b54d3e08 to your computer and use it in GitHub Desktop.
Little test program to write out timestamps in ASCII as fast as possible (for testing ISS writing data issues)
//
// ascii-data-printer
//
// Created by Stuart Campbell on 3/9/18.
// Copyright © 2018 Stuart Campbell. All rights reserved.
//
#include <iostream>
#include <stdio.h>
#include <time.h>
#include <thread>
#include <chrono>
//const int NUM_SECONDS = 10;
int main(int argc, const char * argv[]) {
long long sleep_duration = 100;
if ( argc != 2 ) { // argc should be 2 for correct execution
// We print argv[0] assuming it is the program name
std::cout<<"usage: "<< argv[0] <<" <sleep-duration-in-usec>\n" <<std::endl;
std::cout << " Using a default time of 100 usec" << std::endl;
}
else {
sleep_duration = (long long)(argv[1]);
}
while(true)
{
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
auto nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch());
std::this_thread::sleep_for(std::chrono::microseconds(sleep_duration));
//std::cout << nanoseconds.count() << std::endl;
printf("%lld\n", nanoseconds.count());
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment