Coder Social home page Coder Social logo

epoch's Introduction

Epoch

Epoch is a high resolution, cross platform time library for C/C++. This library can provide time measurements of less than one microsecond (1E-6 seconds), as well as date and time information in both local and UTC time. See examples at the end to see the proper usage of functions and what header files to include.

Data types:

Epoch_t

  • Essentially acts as a timer to hold elapsed time info

Epoch_SysInfo_t

  • Holds current system time information.

      typedef struct
      {
      unsigned short year;      // current year
      unsigned short month;     // current month (0-11)
      unsigned short weekday;   // current weekday (0-6)
      unsigned short day;       // current day (0-364)
      unsigned short hour;      // current hour (0-23)
      unsigned short minute;    // current minute (0-59)
      unsigned short second;    // current second (0-59)
      } Epoch_SysInfo_t;
    

Constants:

EPOCH_LOCAL_TIME

  • Used to query system time information in local time (the time on your machine).

EPOCH_UTC_TIME

  • Used to query system time information in universal coordinated time (UTC).

Functions:

unsigned char Epoch__Init();

  • Intializes internal variables for use. Needs to be called only once at the start of the program.

void Epoch__Start(Epoch_t*);

  • Initializes an Epoch_t and resets it's elapsed time. This must be called to start an Epoch_t before it's elapsed time is ever queried.

double Epoch__QueryChange(Epoch_t*);

  • Gets the elapsed time from an Epoch_t.

void Epoch__QuerySysInfo(Epoch_SysInfo_t*, unsigned char type);

  • Fill a Epoch_SysInfo_t with system time information. "type" should be either EPOCH_LOCAL_TIME or EPOCH_UTC_TIME.

Examples:

Run a loop for five seconds

#include <stdio.h>
#include "epoch.h"

int main(int argc, char* argv[])
{
    // Initialize Epoch
    Epoch__Init();

    // Create a new timer
    Epoch_t timer;

    // Start the timer
    Epoch__Start(&timer);
    // Keep track of elapsed time
    double elapsed;

    // Print out elapsed time
    // for five seconds
    do
    {
        // Get change in time since the
        // timer was started
        elapsed = Epoch__QueryChange(&timer);
        printf("%f\n", elapsed);
    }
    while (elapsed < 5.0);
}

Get local time info

#include <stdio.h>
#include "epoch.h"

int main(int argc, char* argv[])
{
    // Initialize Epoch
    Epoch__Init();

    // Used to hold system information
    Epoch_SysInfo_t info;

    // Get current system information (local time)
    Epoch__QuerySysInfo(&info, EPOCH_LOCAL_TIME);

    // Print some info
    printf("Current Year: %d\n", info.year);
    printf("Current Month: %d\n", info.month);
    printf("Current Weekday: %d\n", info.weekday);
    printf("Current Day: %d\n", info.day);
    printf("Current Hour: %d\n", info.hour);
    printf("Current Minute: %d\n", info.minute);
    printf("Current Second: %d\n", info.second);
}

epoch's People

Contributors

seanjackson6325 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.