Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
4lDO2
acid
Commits
9faaf3a9
Commit
9faaf3a9
authored
Oct 21, 2016
by
Jeremy Soller
Browse files
Simpler switch test
parent
bbb5d70e
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main.rs
View file @
9faaf3a9
...
...
@@ -4,30 +4,29 @@ extern crate x86;
fn
switch_test
()
->
Result
<
(),
String
>
{
use
std
::
thread
;
use
std
::
time
::
Instant
;
use
x86
::
time
::
rdtscp
;
let
switch_thread
=
thread
::
spawn
(||
{
for
i
in
0
..
100
{
let
time
=
Instant
::
now
();
let
tsc
=
unsafe
{
rdtscp
()
};
let
tsc
=
unsafe
{
rdtscp
()
};
let
switch_thread
=
thread
::
spawn
(||
->
usize
{
let
mut
j
=
0
;
while
j
<
500
{
thread
::
yield_now
();
let
dtsc
=
unsafe
{
rdtscp
()
}
-
tsc
;
let
dtime
=
time
.elapsed
();
print!
(
"{}"
,
format!
(
"C: {}: {} ns: {} ticks
\n
"
,
i
,
dtime
.as_secs
()
*
1000000000
+
dtime
.subsec_nanos
()
as
u64
,
dtsc
));
j
+=
1
;
}
j
});
for
i
in
0
..
100
{
let
time
=
Instant
::
now
();
let
tsc
=
unsafe
{
rdtscp
()
};
let
mut
i
=
0
;
while
i
<
500
{
thread
::
yield_now
();
let
dtsc
=
unsafe
{
rdtscp
()
}
-
tsc
;
let
dtime
=
time
.elapsed
();
print!
(
"{}"
,
format!
(
"P: {}: {} ns: {} ticks
\n
"
,
i
,
dtime
.as_secs
()
*
1000000000
+
dtime
.subsec_nanos
()
as
u64
,
dtsc
));
i
+=
1
;
}
let
_
=
switch_thread
.join
();
let
j
=
switch_thread
.join
()
.unwrap
();
let
dtsc
=
unsafe
{
rdtscp
()
}
-
tsc
;
println!
(
"P {} C {} T {}"
,
i
,
j
,
dtsc
);
Ok
(())
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment