start-bench.dhover×100all
#!/usr/bin/env dub
/+ dub.sdl:
    name "android-research-start-bench"
    platforms "linux"
    dflags "-betterC"
    targetPath "build"
    buildType "checked" {
        buildOptions "optimize" "inline" "debugInfo"
    }
+/
/**
E7's bounded process-start microbenchmark: five trials of 1,000 fork/exec/waits.
Default invocation does nothing. --run PROGRAM [ARGS...] runs that exact argv
under the caller's actual app domain, stopping on the first failed child.
See ../index.md#current-target-experiments. Run only with owner approval.
*/
module 
(module) start_bench

E7's bounded process-start microbenchmark: five trials of 1,000 fork/exec/waits. Default invocation does nothing. --run PROGRAM [ARGS...] runs that exact argv under the caller's actual app domain, stopping on the first failed child. See ../index.md#current-target-experiments. Run only with owner approval.

start_bench
;
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.errno

D header file for C99.

pubs.opengroup.org/onlinepubs/009695399/basedefs/errno.h.html, errno.h

Source

core/stdc/errno.d

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly, Alex Rønne Petersen@standardsISO/IEC 9899:1999 (E)
errno
:
(alias) start_bench.errno = int core.stdc.errno.__errno_location() nothrow @nogc ref @trusted
errno
,
(alias constant) start_bench.EINTR = int core.stdc.errno.EINTR = 4
EINTR
;
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.stdio

D header file for C99 <stdio.h>

pubs.opengroup.org/onlinepubs/009695399/basedefs/stdio.h.html, stdio.h

Source

core/stdc/stdio.d

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly, Alex Rønne Petersen@standardsISO/IEC 9899:1999 (E)
stdio
:
(alias) start_bench.printf = int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
,
(alias) start_bench.fflush = int core.stdc.stdio.fflush(shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogc @trusted
fflush
;
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.string

D header file for C99.

pubs.opengroup.org/onlinepubs/009695399/basedefs/string.h.html, string.h

Source

core/stdc/string.d

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly@standardsISO/IEC 9899:1999 (E)
string
:
(alias) start_bench.strcmp = int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogc
strcmp
;
import
(package) core
core
.
(package) core.sys
sys
.
(package) core.sys.posix
posix
.
(package) core.sys.posix.sys
sys
.
(module) core.sys.posix.sys.wait

D header file for POSIX.

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseBoost License 1.0.@authorsSean Kelly, Alex Rønne Petersen@standardsThe Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
wait
:
(alias) start_bench.waitpid = int core.sys.posix.sys.wait.waitpid(int, int*, int) nothrow @nogc
waitpid
;
import
(package) core
core
.
(package) core.sys
sys
.
(package) core.sys.posix
posix
.
(module) core.sys.posix.time

D header file for POSIX.

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseBoost License 1.0.@authorsSean Kelly, Alex Rønne Petersen@standardsThe Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
time
:
(alias) start_bench.clock_gettime = int core.sys.posix.time.clock_gettime(int, core.sys.posix.time.timespec*) nothrow @nogc
clock_gettime
,
(alias constant) start_bench.CLOCK_MONOTONIC = int core.sys.posix.time.CLOCK_MONOTONIC = 1
CLOCK_MONOTONIC
,
(struct) core.sys.posix.time.timespec
timespec
;
import
(package) core
core
.
(package) core.sys
sys
.
(package) core.sys.posix
posix
.
(module) core.sys.posix.unistd

D header file for POSIX.

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseBoost License 1.0.@authorsSean Kelly@standardsThe Open Group Base Specifications Issue 8, IEEE Std 1003.1, 2024 Edition
unistd
:
(alias) start_bench.fork = int core.sys.posix.unistd.fork() nothrow @nogc @trusted
fork
,
(alias) start_bench.execve = int core.sys.posix.unistd.execve(scope const(char*), scope const(char**), scope const(char**)) nothrow @nogc
execve
,
(alias) start_bench._exit = noreturn core.sys.posix.unistd._exit(int) nothrow @nogc @trusted
_exit
;
extern(C) extern __gshared char**
(__gshared global) char** start_bench.environ
environ
;
extern(C) int
int start_bench.main(int argc, char** argv) nothrow @nogc @system
main
(int
(parameter) int argc
argc
, char**
(parameter) char** argv
argv
) @system nothrow @nogc
{ if (
(parameter) int argc
argc
< 3 ||
int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogc
strcmp
(
(parameter) char** argv
argv
[1], "--run") != 0)
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("SKIP: pass --run PROGRAM [ARGS...] for an approved benchmark.\n");
return 0; } enum
(constant) int start_bench.main.count = 1000
count
= 1000;
foreach (
(local variable) int trial
trial
; 0 .. 5)
{
(struct) core.sys.posix.time.timespec
timespec
(local variable) core.sys.posix.time.timespec start
start
,
(local variable) core.sys.posix.time.timespec end
end
;
if (
int core.sys.posix.time.clock_gettime(int, core.sys.posix.time.timespec*) nothrow @nogc
clock_gettime
(
(constant) int core.sys.posix.time.CLOCK_MONOTONIC = 1
CLOCK_MONOTONIC
, &
(local variable) core.sys.posix.time.timespec start
start
) != 0)
return 1; foreach (
(local variable) int i
i
; 0 ..
(constant) int start_bench.main.count = 1000
count
)
{ const
(local variable) const(int) child
child
=
int core.sys.posix.unistd.fork() nothrow @nogc @trusted
fork
();
if (
(local variable) const(int) child
child
< 0)
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("fork: errno=%d\n",
int core.stdc.errno.__errno_location() nothrow @nogc ref @trusted
errno
);
return 1; } if (
(local variable) const(int) child
child
== 0)
{
int core.sys.posix.unistd.execve(scope const(char*), scope const(char**), scope const(char**)) nothrow @nogc
execve
(
(parameter) char** argv
argv
[2], cast(const(char)**) (
(parameter) char** argv
argv
+ 2), cast(const(char)**)
(__gshared global) char** start_bench.environ
environ
);
noreturn core.sys.posix.unistd._exit(int) nothrow @nogc @trusted
_exit
(127);
} int
(local variable) int status
status
;
int
(local variable) int result
result
;
do
(local variable) int result
result
=
int core.sys.posix.sys.wait.waitpid(int, int*, int) nothrow @nogc
waitpid
(
(local variable) const(int) child
child
, &
(local variable) int status
status
, 0);
while (
(local variable) int result
result
< 0 &&
int core.stdc.errno.__errno_location() nothrow @nogc ref @trusted
errno
==
int core.stdc.errno.__errno_location() nothrow @nogc ref @trusted
EINTR
);
if (
(local variable) int result
result
!=
(local variable) const(int) child
child
||
(local variable) int status
status
!= 0)
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("trial=%d iteration=%d wait=%d status=%d\n",
(local variable) int trial
trial
+ 1,
(local variable) int i
i
,
(local variable) int result
result
,
(local variable) int status
status
);
return 1; } } if (
int core.sys.posix.time.clock_gettime(int, core.sys.posix.time.timespec*) nothrow @nogc
clock_gettime
(
(constant) int core.sys.posix.time.CLOCK_MONOTONIC = 1
CLOCK_MONOTONIC
, &
(local variable) core.sys.posix.time.timespec end
end
) != 0)
return 1; const
(local variable) const(long) ns
ns
= (
(local variable) core.sys.posix.time.timespec end
end
.
(field) long core.sys.posix.time.timespec.tv_sec
tv_sec
-
(local variable) core.sys.posix.time.timespec start
start
.
(field) long core.sys.posix.time.timespec.tv_sec
tv_sec
) * 1_000_000_000L +
(local variable) core.sys.posix.time.timespec end
end
.
(field) long core.sys.posix.time.timespec.tv_nsec
tv_nsec
-
(local variable) core.sys.posix.time.timespec start
start
.
(field) long core.sys.posix.time.timespec.tv_nsec
tv_nsec
;
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("trial=%d successful=%d elapsed-ns=%lld ns-per-start=%lld\n",
(local variable) int trial
trial
+ 1,
(constant) int start_bench.main.count = 1000
count
, cast(long)
(local variable) const(long) ns
ns
, cast(long) (
(local variable) const(long) ns
ns
/
(constant) int start_bench.main.count = 1000
count
));
int core.stdc.stdio.fflush(shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogc @trusted
fflush
(null);
} return 0; }