| 1 | /* $Id: PrfTstProcess-2.c,v 1.1 2003-05-01 11:20:49 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-2003 knut st. osmundsen (bird@anduin.net) | 
|---|
| 7 | * | 
|---|
| 8 | * GPL | 
|---|
| 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 | * | 
|---|
| 23 | * @subsection  Compilation OS/2 | 
|---|
| 24 | * Just as normal odin apps:<br> | 
|---|
| 25 | * nmake -f prftstprocess-2.mak | 
|---|
| 26 | *  or | 
|---|
| 27 | * wcl386 -d__OS2__=1 -bt=os2v2 /los2v2 -I%WATCOM\h\os2 PrfTstProcess-2.c | 
|---|
| 28 | * | 
|---|
| 29 | * @subsection  Complation NT | 
|---|
| 30 | * This works from OS/2 and NT: | 
|---|
| 31 | * wcl386 -d__WINNT__=1 -bt=nt /lnt -I%WATCOM\h\nt PrfTstProcess-2.c   kernel32.lib | 
|---|
| 32 | * | 
|---|
| 33 | * Optimized: | 
|---|
| 34 | * wcl386 -Otx -d__WINNT__=1 -bt=nt /lnt -I%WATCOM\h\nt PrfTstProcess-2.c   kernel32.lib | 
|---|
| 35 | * | 
|---|
| 36 | */ | 
|---|
| 37 |  | 
|---|
| 38 | #include "PrfTiming.h" | 
|---|
| 39 |  | 
|---|
| 40 |  | 
|---|
| 41 | int main(int argc, char **argv) | 
|---|
| 42 | { | 
|---|
| 43 | long double rdCur; | 
|---|
| 44 | long double rdStart; | 
|---|
| 45 | long double rdEnd; | 
|---|
| 46 | unsigned    cChilds; | 
|---|
| 47 | int         pid; | 
|---|
| 48 | #ifdef __NOTPC__ | 
|---|
| 49 | int         status; | 
|---|
| 50 | #endif | 
|---|
| 51 |  | 
|---|
| 52 | /* | 
|---|
| 53 | * Child process test. | 
|---|
| 54 | */ | 
|---|
| 55 | if (argc != 1) | 
|---|
| 56 | return 0; | 
|---|
| 57 |  | 
|---|
| 58 | /* | 
|---|
| 59 | * Main process. | 
|---|
| 60 | */ | 
|---|
| 61 | cChilds = 0;                        /* child count */ | 
|---|
| 62 | rdEnd = getHz() * 20.0;             /* loop for 20 seconds */ | 
|---|
| 63 | rdStart = rdCur = gettime(); | 
|---|
| 64 | rdEnd += gettime(); | 
|---|
| 65 | while (rdEnd > rdCur) | 
|---|
| 66 | { | 
|---|
| 67 | #ifndef __NOTPC__ | 
|---|
| 68 | pid = spawnl(P_WAIT, argv[0], argv[0], "child", NULL); /* pid == 0 on success */ | 
|---|
| 69 | #else | 
|---|
| 70 | pid = fork(); | 
|---|
| 71 | if (pid == 0) | 
|---|
| 72 | {/* child code */ | 
|---|
| 73 | execl(argv[0], argv[0], "child", NULL); | 
|---|
| 74 | fprintf(stderr, "we should NEVER be here!!\n"); | 
|---|
| 75 | return 0; | 
|---|
| 76 | } | 
|---|
| 77 | if (pid > 0) | 
|---|
| 78 | pid = wait(&status); | 
|---|
| 79 | #endif | 
|---|
| 80 | cChilds++; | 
|---|
| 81 | rdCur = gettime(); | 
|---|
| 82 | } | 
|---|
| 83 | printf("Spawned %d childs in %Lf seconds\n", cChilds, (rdCur - rdStart) / getHz()); | 
|---|
| 84 | printSystemInfo(); | 
|---|
| 85 | return 0; | 
|---|
| 86 | } | 
|---|