File: example_sphtimer.c

package info (click to toggle)
sphde 1.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 4,400 kB
  • sloc: ansic: 38,652; cpp: 20,246; sh: 11,427; makefile: 252
file content (51 lines) | stat: -rw-r--r-- 1,347 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * Copyright (c) 2014 IBM Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

#include <stdio.h>
#include <time.h>

#include <sphde/sphtimer.h>

/*
 * This is example showing the sphtimer.h usage and machine timer resolution.
 */

int
main (int argc, char *argv[])
{
  sphtimer_t timer_freg = sphfastcpufreq ();
  sphtimer_t timer_val = sphgettimer ();
  sphtimer_t before, after;
  struct timespec t100ms = { 0, 100000000L };
  struct timespec t1000ms = { 1, 0 };
  double seconds;

  printf ("Time Base Frequency = %lld\nTime Base value = %lld\n\n",
    timer_freg, timer_val);

  /* warm up PLT */
  nanosleep (&t100ms, NULL);

  printf ("nanosleep  100ms - ");
  before = sphgettimer ();
  nanosleep (&t100ms, NULL);
  after = sphgettimer ();

  seconds = (double) (after - before) / (double) timer_freg;
  printf ("delta=%012lld %f sec\n", (after - before), seconds);

  printf ("nanosleep 1000ms - ");
  before = sphgettimer ();
  nanosleep (&t1000ms, NULL);
  after = sphgettimer ();

  seconds = (double) (after - before) / (double) timer_freg;
  printf ("delta=%012lld %f sec\n", (after - before), seconds);

  return 0;
}