00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00045
00046 #include <benchs.h>
00047 #include <stddef.h>
00048
00049
00050 void
00051 bench_list (bench_t *b)
00052 {
00053 struct list {
00054 struct list *next;
00055 };
00056 struct list elts[100];
00057 struct list *first;
00058 struct list *n;
00059 int i;
00060
00061
00062 bench_start (b);
00063 first = 0;
00064 for (i = 0; i < 100; i++)
00065 {
00066 elts[i].next = first;
00067 first = &elts[i];
00068 }
00069 bench_stop (b);
00070 bench_report (b, "Single linked list init (100 elts)");
00071
00072
00073 i = 0;
00074 bench_start (b);
00075 for (n = first; n; n = n->next)
00076 i++;
00077 bench_stop (b);
00078 bench_report (b, "Scan list %d elts", (long) i);
00079 }
00080
00081 const char *bench_string = "Hello World!";
00082
00083
00084 void
00085 bench_strlen (bench_t *b)
00086 {
00087 size_t l;
00088
00089
00090 bench_start (b);
00091 l = strlen ("Hello World!");
00092 bench_stop (b);
00093 bench_report (b, "strlen const string %d", (long) l);
00094
00095 bench_start (b);
00096 l = strlen (bench_string);
00097 bench_stop (b);
00098 bench_report (b, "strlen %d", (long) l);
00099 }
00100
00101 unsigned short
00102 fact_ushort (unsigned short n)
00103 {
00104 if (n > 0)
00105 return n * fact_ushort (n - 1);
00106 else
00107 return 1;
00108 }
00109
00110 unsigned long
00111 fact_ulong (unsigned long n)
00112 {
00113 if (n > 0)
00114 return n * fact_ulong (n - 1);
00115 else
00116 return 1;
00117 }
00118
00119 void
00120 bench_fact (bench_t *b)
00121 {
00122 unsigned short f;
00123 unsigned long fl;
00124
00125 bench_start (b);
00126 f = fact_ushort (8);
00127 bench_stop (b);
00128 bench_report (b, "fact(8) unsigned short (%d)", (long) f);
00129
00130 bench_start (b);
00131 fl = fact_ulong (12);
00132 bench_stop (b);
00133 bench_report (b, "fact(12) unsigned long (%d)", fl);
00134 }
00135
00136
00137 int
00138 main ()
00139 {
00140 bench_t b;
00141
00142 bench_init (&b);
00143 bench_list (&b);
00144 bench_strlen (&b);
00145 bench_fact (&b);
00146 return 0;
00147 }