File: testprofile.c

package info (click to toggle)
mmlib 1.4.2-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,716 kB
  • sloc: ansic: 18,071; makefile: 431; sh: 135; python: 63
file content (99 lines) | stat: -rw-r--r-- 1,758 bytes parent folder | download
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
   @mindmaze_header@
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif


#include "mmprofile.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

#define OUTFD	1 //STDOUT_FILENO

static
void print_profile(void)
{
	int i, j;
	volatile int x;

	for (i = 0; i < 100; i++) {
		x = 2;
		mm_tic();
		x /= 2;
		if (x == 1)
			x /= 10;
		mm_toc();
		for (j = 0; j < 10; j++)
			x *= 2;
		mm_toc();
		x = 2;
		for (j = 0; j < 50; j++)
			x *= 2;
		mm_toc();
	}

	mm_profile_print(PROF_MEAN|PROF_MIN|PROF_MAX, OUTFD);
	mm_profile_print(PROF_DEFAULT|PROF_FORCE_NSEC, OUTFD);
	mm_profile_print(PROF_DEFAULT|PROF_FORCE_USEC, OUTFD);
	mm_profile_print(PROF_DEFAULT|PROF_FORCE_MSEC, OUTFD);
	mm_profile_print(PROF_DEFAULT|PROF_FORCE_SEC, OUTFD);
}


static
void print_profile_labelled(void)
{
	int i, j;
	volatile int x;

	for (i = 0; i < 100; i++) {
		x = 2;
		mm_tic();
		x /= 2;
		if (x == 1)
			x /= 10;
		mm_toc_label("First step");
		for (j = 0; j < 10; j++)
			x *= 2;
		mm_toc_label("Second step");
		x = 2;
		for (j = 0; j < 50; j++)
			x *= 2;
		mm_toc_label("Last step");
	}

	mm_profile_print(PROF_MEAN|PROF_MIN|PROF_MAX, OUTFD);
}


int main(void)
{
	printf("Timing with default settings\n");
	fflush(stdout);
	print_profile();

	printf("\nTiming with wall clock timer\n");
	fflush(stdout);
	mm_profile_reset(0);
	print_profile();

	printf("\nTiming with CPU based timer\n");
	fflush(stdout);
	mm_profile_reset(PROF_RESET_CPUCLOCK);
	print_profile();

	printf("\nLabelled mm_toc() 1st\n");
	fflush(stdout);
	mm_profile_reset(PROF_RESET_CPUCLOCK);
	print_profile_labelled();

	printf("\nLabelled mm_toc() label kept\n");
	fflush(stdout);
	mm_profile_reset(PROF_RESET_CPUCLOCK|PROF_RESET_KEEPLABEL);
	print_profile_labelled();

	return EXIT_SUCCESS;
}