こんなコードを書いて,Linux,Minixでかかる時間をtimeコマンドで見てみました.
#include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <sys/types.h> #include <sys/wait.h> int main(int argc, char **argv) { pid_t pid; int max; int i; int pfd[2]; char buf[16]; if (argc != 1) max = atoi(argv[1]); for (i = 0; i < max; i++) { if (pipe(pfd) < 0) { printf("pipe error\n"); exit(-1); } pid = fork(); if (pid < 0) { printf("fork error\n"); exit(-1); } else if(!pid) { /* child */ read(pfd[0], buf, 16); close(pfd[0]); close(pfd[1]); _exit(0); } else { /* parent */ close(pfd[0]); write(pfd[1], "hello", 6); close(pfd[1]); wait(NULL); } } putchar('\n'); return 0; }
maxは10,000にして実行しました.メモリに関しては,仮想環境が128MB,実機は4GBです.
結果はこんな感じです.
環境 | real | user | sys | |
---|---|---|---|---|
Linux 2.6.33-rc5(実機) | 2.24 | 0.00 | 0.78 | |
Minix 3.1.0(kvm) | 0.45 | 0.03 | 0.40 | |
Minix 3.1.0(no-kvm) | 6.75 | 0.35 | 6.01 | |
Linux 2.6.33-rc2(kvm) | 4.545 | 0.056 | 1.552 | |
Linux 2.6.33-rc2(no-kvm) | 3.247 | 0.248 | 4.992 |
あれ,Minixが意外と速い・・・