| 1 | /* $Id: PrfTstProcess.c,v 1.2 2001-07-30 01:56:28 bird Exp $
|
|---|
| 2 | *
|
|---|
| 3 | * Test program which checks how long it takes to execute another
|
|---|
| 4 | * instance of itself and run
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright (c) 2001 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
|---|
| 7 | *
|
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 9 | *
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 | /** @design Process Startup and Termination cost.
|
|---|
| 13 | *
|
|---|
| 14 | * The purpose is to compare the cost of creating a child process on different
|
|---|
| 15 | * platforms; revealing which is the best ones...
|
|---|
| 16 | *
|
|---|
| 17 | * Later analysis on why will be done I hope...
|
|---|
| 18 | *
|
|---|
| 19 | *
|
|---|
| 20 | * @subsection Test Results
|
|---|
| 21 | *
|
|---|
| 22 | * Linux version 2.4.5 (SMP) Pentium III 700Mhz- GCC:
|
|---|
| 23 | * 0.001845 - 0.001845 sec (pid=193c)
|
|---|
| 24 | * 0.001832 - 0.001832 sec (pid=193e)
|
|---|
| 25 | * 0.001792 - 0.001792 sec (pid=1940)
|
|---|
| 26 | * 0.001899 - 0.001899 sec (pid=1942)
|
|---|
| 27 | *
|
|---|
| 28 | * OS/2 WS4eB 4.5 FP 2 (SMP) Pentium III 600Mhz - Watcom -Otx:
|
|---|
| 29 | * 5150.000000 - 0.004316 sec (pid=0)
|
|---|
| 30 | * 5175.000000 - 0.004337 sec (pid=0)
|
|---|
| 31 | * 5143.000000 - 0.004310 sec (pid=0)
|
|---|
| 32 | * 5181.000000 - 0.004342 sec (pid=0)
|
|---|
| 33 | *
|
|---|
| 34 | * OS/2 WS4eB 4.5 FP 2 (SMP) Pentium III 600Mhz - Watcom (no optimization):
|
|---|
| 35 | * 5510.000000 - 0.004618 sec (pid=0)
|
|---|
| 36 | * 5500.000000 - 0.004610 sec (pid=0)
|
|---|
| 37 | * 5489.000000 - 0.004600 sec (pid=0)
|
|---|
| 38 | * 5551.000000 - 0.004652 sec (pid=0)
|
|---|
| 39 | *
|
|---|
| 40 | * OS/2 WS4eB 4.5 FP 2 (SMP) Pentium III 600Mhz - VAC308:
|
|---|
| 41 | * 6490.000000 - 0.005439 sec (pid=0)
|
|---|
| 42 | * 6465.000000 - 0.005418 sec (pid=0)
|
|---|
| 43 | * 6501.000000 - 0.005449 sec (pid=0)
|
|---|
| 44 | * 6496.000000 - 0.005444 sec (pid=0)
|
|---|
| 45 | *
|
|---|
| 46 | * OS/2 WS4eB 4.5 FP 2 (SMP) Pentium III 600Mhz - VAC365:
|
|---|
| 47 | * 6743.000000 - 0.005651 sec (pid=0)
|
|---|
| 48 | * 6694.000000 - 0.005610 sec (pid=0)
|
|---|
| 49 | * 6705.000000 - 0.005619 sec (pid=0)
|
|---|
| 50 | * 7025.000000 - 0.005888 sec (pid=0)
|
|---|
| 51 | *
|
|---|
| 52 | * OS/2 WS4eB 4.5 FP 2 (SMP) Pentium III 600Mhz - EMX -D__OS2__:
|
|---|
| 53 | * 15339.000000 - 0.012856 sec (pid=0)
|
|---|
| 54 | * 15507.000000 - 0.012997 sec (pid=0)
|
|---|
| 55 | * 15224.000000 - 0.012759 sec (pid=0)
|
|---|
| 56 | * 15714.000000 - 0.013170 sec (pid=0)
|
|---|
| 57 | *
|
|---|
| 58 | * OS/2 WS4eB 4.5 FP 2 (SMP) Pentium III 600Mhz - EMX -D__OS2__ -D__NOTPC__:
|
|---|
| 59 | * 31992.000000 - 0.026813 sec (pid=1c7f)
|
|---|
| 60 | * 32300.000000 - 0.027071 sec (pid=1c82)
|
|---|
| 61 | * 31699.000000 - 0.026567 sec (pid=1c85)
|
|---|
| 62 | * 33570.000000 - 0.028135 sec (pid=1c88)
|
|---|
| 63 | *
|
|---|
| 64 | */
|
|---|
| 65 |
|
|---|
| 66 | #include <stdio.h>
|
|---|
| 67 | #include <sys/time.h>
|
|---|
| 68 | #ifndef __NOTPC__
|
|---|
| 69 | #include <process.h>
|
|---|
| 70 | #endif
|
|---|
| 71 |
|
|---|
| 72 | #ifdef __OS2__
|
|---|
| 73 | #define INCL_DOSPROFILE
|
|---|
| 74 | #include <os2.h>
|
|---|
| 75 |
|
|---|
| 76 | long double gettime(void)
|
|---|
| 77 | {
|
|---|
| 78 | QWORD qw;
|
|---|
| 79 | DosTmrQueryTime(&qw);
|
|---|
| 80 | return (long double)qw.ulHi * (4294967296.00) + qw.ulLo;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | unsigned getHz(void)
|
|---|
| 84 | {
|
|---|
| 85 | ULONG ul = -1;
|
|---|
| 86 | DosTmrQueryFreq(&ul);
|
|---|
| 87 | return ul;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 | #elif defined(__WINNT__)
|
|---|
| 92 | /*
|
|---|
| 93 | * Windows
|
|---|
| 94 | */
|
|---|
| 95 | unsigned long __stdcall GetTickCount(void);
|
|---|
| 96 |
|
|---|
| 97 | long double gettime(void)
|
|---|
| 98 | {
|
|---|
| 99 | return (long double)GetTickCount();
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | unsigned getHz(void)
|
|---|
| 103 | {
|
|---|
| 104 | return 1000;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 | #else
|
|---|
| 109 |
|
|---|
| 110 | long double gettime(void)
|
|---|
| 111 | {
|
|---|
| 112 | struct timeval tp;
|
|---|
| 113 | long sec = 0L;
|
|---|
| 114 |
|
|---|
| 115 | if (gettimeofday(&tp, NULL))
|
|---|
| 116 | return -1;
|
|---|
| 117 | return tp.tv_usec / 1000000.00 + tp.tv_sec;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | unsigned getHz(void)
|
|---|
| 121 | {
|
|---|
| 122 | return 1;//000000;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | #endif
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 | int main(int argc, char **argv)
|
|---|
| 129 | {
|
|---|
| 130 | long double rdStart;
|
|---|
| 131 | long double rdEnd;
|
|---|
| 132 | int pid;
|
|---|
| 133 | #ifdef __NOTPC__
|
|---|
| 134 | int status;
|
|---|
| 135 | #endif
|
|---|
| 136 |
|
|---|
| 137 | /*
|
|---|
| 138 | * Child process test.
|
|---|
| 139 | */
|
|---|
| 140 | if (argc != 1)
|
|---|
| 141 | return 0;
|
|---|
| 142 |
|
|---|
| 143 | /*
|
|---|
| 144 | * Main process.
|
|---|
| 145 | */
|
|---|
| 146 | rdStart = gettime();
|
|---|
| 147 | #ifndef __NOTPC__
|
|---|
| 148 | pid = spawnl(P_WAIT, argv[0], argv[0], "child", NULL); /* pid == 0 on success */
|
|---|
| 149 | #else
|
|---|
| 150 | pid = fork();
|
|---|
| 151 | if (pid == 0)
|
|---|
| 152 | {/* child code */
|
|---|
| 153 | execl(argv[0], argv[0], "child", NULL);
|
|---|
| 154 | fprintf(stderr, "we should NEVER be here!!\n");
|
|---|
| 155 | return 0;
|
|---|
| 156 | }
|
|---|
| 157 | if (pid > 0)
|
|---|
| 158 | pid = wait(&status);
|
|---|
| 159 | #endif
|
|---|
| 160 | rdEnd = gettime();
|
|---|
| 161 | printf("%Lf - %Lf sec (pid=%x)\n", rdEnd - rdStart, (rdEnd - rdStart) / getHz(), pid);
|
|---|
| 162 | printf("(start: %Lf end: %Lf Hz: %d\n", rdStart, rdEnd, getHz());
|
|---|
| 163 |
|
|---|
| 164 | return 0;
|
|---|
| 165 | }
|
|---|