| 1 | /* $Id: PrfTstProcess-3.c,v 1.1 2003-05-01 11:20:50 bird Exp $ | 
|---|
| 2 | * | 
|---|
| 3 | * Test program which checks how long it takes to execute another process. | 
|---|
| 4 | * | 
|---|
| 5 | * Copyright (c) 2001-2003 knut st. osmundsen (bird@anduin.net) | 
|---|
| 6 | * | 
|---|
| 7 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 8 | * | 
|---|
| 9 | */ | 
|---|
| 10 |  | 
|---|
| 11 | /** @design Process Startup and Termination cost. | 
|---|
| 12 | * | 
|---|
| 13 | * The purpose is to compare the cost of creating a child process on different | 
|---|
| 14 | * platforms; revealing which is the best ones... | 
|---|
| 15 | * | 
|---|
| 16 | * Later analysis on why will be done I hope... | 
|---|
| 17 | * | 
|---|
| 18 | * | 
|---|
| 19 | * @subsection Test Results | 
|---|
| 20 | * | 
|---|
| 21 | * | 
|---|
| 22 | * @subsection  Compilation OS/2 | 
|---|
| 23 | * Just as normal odin apps:<br> | 
|---|
| 24 | * wcl386 -d__OS2__=1 -bt=os2v2 /los2v2 -I%WATCOM\h\os2 PrfTstProcess-3.c | 
|---|
| 25 | * wcl386 -d__OS2__=1 -bt=os2v2 /los2v2 -I%WATCOM\h\os2 PrfTstProcess-3-child.c | 
|---|
| 26 | * | 
|---|
| 27 | * @subsection  Complation NT | 
|---|
| 28 | * This works from OS/2 and NT: | 
|---|
| 29 | * wcl386 -d__WINNT__=1 -bt=nt /lnt -I%WATCOM\h\nt PrfTstProcess-3.c   kernel32.lib | 
|---|
| 30 | * wcl386 -d__WINNT__=1 -bt=nt /lnt -I%WATCOM\h\nt PrfTstProcess-3-child.c | 
|---|
| 31 | * | 
|---|
| 32 | * Optimized: | 
|---|
| 33 | *  Add -Otx | 
|---|
| 34 | * | 
|---|
| 35 | */ | 
|---|
| 36 |  | 
|---|
| 37 | #include "PrfTiming.h" | 
|---|
| 38 |  | 
|---|
| 39 | int main(int argc, char **argv) | 
|---|
| 40 | { | 
|---|
| 41 | long double rdCur; | 
|---|
| 42 | long double rdStart; | 
|---|
| 43 | long double rdEnd; | 
|---|
| 44 | unsigned    cChilds; | 
|---|
| 45 | int         pid; | 
|---|
| 46 | #ifdef __NOTPC__ | 
|---|
| 47 | int         status; | 
|---|
| 48 | #endif | 
|---|
| 49 | char        szChild[256]; | 
|---|
| 50 |  | 
|---|
| 51 |  | 
|---|
| 52 | /* | 
|---|
| 53 | * Mainloop. | 
|---|
| 54 | */ | 
|---|
| 55 | strcpy(szChild, argv[0]); | 
|---|
| 56 | #ifdef __NOTPC__ | 
|---|
| 57 | strcat(szChild, "-child"); | 
|---|
| 58 | #else | 
|---|
| 59 | if (!stricmp(szChild + strlen(szChild) - 4, ".exe")) | 
|---|
| 60 | szChild[strlen(szChild) - 4] = '\0'; | 
|---|
| 61 | strcat(szChild, "-child.exe"); | 
|---|
| 62 | #endif | 
|---|
| 63 |  | 
|---|
| 64 | cChilds = 0;                        /* child count */ | 
|---|
| 65 | rdEnd = getHz() * 20.0;             /* loop for 20 seconds */ | 
|---|
| 66 | rdStart = rdCur = gettime(); | 
|---|
| 67 | rdEnd += gettime(); | 
|---|
| 68 | while (rdEnd > rdCur) | 
|---|
| 69 | { | 
|---|
| 70 | #ifndef __NOTPC__ | 
|---|
| 71 | pid = spawnl(P_WAIT, szChild, szChild, "child", NULL); /* pid == 0 on success */ | 
|---|
| 72 | #else | 
|---|
| 73 | pid = fork(); | 
|---|
| 74 | if (pid == 0) | 
|---|
| 75 | {/* child code */ | 
|---|
| 76 | execl(szChild, szChild, "child", NULL); | 
|---|
| 77 | fprintf(stderr, "we should NEVER be here!!\n"); | 
|---|
| 78 | return 0; | 
|---|
| 79 | } | 
|---|
| 80 | #endif | 
|---|
| 81 |  | 
|---|
| 82 | if (pid < 0) | 
|---|
| 83 | { | 
|---|
| 84 | fprintf(stderr, "Failed to spawn child '%s'\n", szChild); | 
|---|
| 85 | return 0; | 
|---|
| 86 | } | 
|---|
| 87 |  | 
|---|
| 88 | #ifdef __NOTPC__ | 
|---|
| 89 | if (pid > 0) | 
|---|
| 90 | pid = wait(&status); | 
|---|
| 91 | #endif | 
|---|
| 92 | cChilds++; | 
|---|
| 93 | rdCur = gettime(); | 
|---|
| 94 | } | 
|---|
| 95 | printf("Spawned %d childs in %Lf seconds\n", cChilds, (rdCur - rdStart) / getHz()); | 
|---|
| 96 | printSystemInfo(); | 
|---|
| 97 | return 0; | 
|---|
| 98 | } | 
|---|