forked from sustrik/libmill
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
- Loading branch information
Showing
10 changed files
with
181 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,6 @@ tests/fdwait | |
tests/tcp | ||
tests/*.trs | ||
tests/*.log | ||
perf/.dirstamp | ||
perf/go | ||
perf/ctxswitch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
Copyright (c) 2015 Martin Sustrik | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom | ||
the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
IN THE SOFTWARE. | ||
*/ | ||
|
||
#include "../libmill.h" | ||
|
||
#include <assert.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <sys/time.h> | ||
|
||
static uint64_t now() { | ||
struct timeval tv; | ||
int rc = gettimeofday(&tv, NULL); | ||
assert(rc == 0); | ||
return ((uint64_t)tv.tv_sec) * 1000 + (((uint64_t)tv.tv_usec) / 1000); | ||
} | ||
|
||
static void worker(long count) { | ||
long i; | ||
for(i = 0; i != count; ++i) | ||
yield(); | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
if(argc != 2) { | ||
printf("usage: ctxswitch <millions-of-context-switches>\n"); | ||
return 1; | ||
} | ||
long count = atol(argv[1]) / 2 * 1000000; | ||
|
||
uint64_t start = now(); | ||
go(worker(count)); | ||
|
||
long i; | ||
for(i = 0; i != count; ++i) | ||
yield(); | ||
|
||
uint64_t stop = now(); | ||
long duration = (long)(stop - start); | ||
long ns = (duration * 1000000) / (count * 2); | ||
|
||
printf("performed %ldM context switches in %f seconds\n", | ||
(long)(count / 1000000 * 2), ((float)duration) / 1000); | ||
printf("duration of one context switch: %ld ns\n", ns); | ||
printf("context switches per second: %fM\n", | ||
(float)(1000000000 / ns) / 1000000); | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Copyright (c) 2015 Martin Sustrik | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom | ||
the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
IN THE SOFTWARE. | ||
*/ | ||
|
||
#include "../libmill.h" | ||
|
||
#include <assert.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <sys/time.h> | ||
|
||
static uint64_t now() { | ||
struct timeval tv; | ||
int rc = gettimeofday(&tv, NULL); | ||
assert(rc == 0); | ||
return ((uint64_t)tv.tv_sec) * 1000 + (((uint64_t)tv.tv_usec) / 1000); | ||
} | ||
|
||
static void worker(void) { | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
if(argc != 2) { | ||
printf("usage: go <millions-of-coroutines>\n"); | ||
return 1; | ||
} | ||
long count = atol(argv[1]) * 1000000; | ||
|
||
uint64_t start = now(); | ||
|
||
long i; | ||
for(i = 0; i != count; ++i) | ||
go(worker()); | ||
|
||
uint64_t stop = now(); | ||
long duration = (long)(stop - start); | ||
long ns = (duration * 1000000) / count; | ||
|
||
printf("performed %ldM coroutines in %f seconds\n", | ||
(long)(count / 1000000 * 2), ((float)duration) / 1000); | ||
printf("duration of one coroutine creation+termination: %ld ns\n", ns); | ||
printf("coroutine creations+terminatios per second: %fM\n", | ||
(float)(1000000000 / ns) / 1000000); | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters