about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-09-01 14:17:11 -0700
committerBrian Anderson <banderson@mozilla.com>2011-09-01 14:20:02 -0700
commitdabf1be2267439d61029b9b9353f4ae2008a3662 (patch)
tree829e2e385c0847879ab4c1f80152cb044d5c3d35 /src/test
parent30447e10919685c490aa5211bbe0dd3059bc8bb4 (diff)
downloadrust-dabf1be2267439d61029b9b9353f4ae2008a3662.tar.gz
rust-dabf1be2267439d61029b9b9353f4ae2008a3662.zip
Add a benchmark for cross-task kernel memory region synchronization
Vectors are allocated from the kernel's memory region, which has some heinous
synchronization. This is a stress test of vector allocation in many tasks.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/bench/task-perf-vector-party.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/bench/task-perf-vector-party.rs b/src/test/bench/task-perf-vector-party.rs
new file mode 100644
index 00000000000..8450405e01c
--- /dev/null
+++ b/src/test/bench/task-perf-vector-party.rs
@@ -0,0 +1,28 @@
+// Vectors are allocated in the Rust kernel's memory region, use of
+// which requires some amount of synchronization. This test exercises
+// that synchronization by spawning a number of tasks and then
+// allocating and freeing vectors.
+
+use std;
+import std::vec;
+import std::uint;
+import std::istr;
+import std::task;
+
+fn f(n: uint) {
+    for each i in uint::range(0u, n) {
+        let v: [u8] = [];
+        vec::reserve(v, 1000u);
+    }
+}
+
+fn main(args: [istr]) {
+    let n = if vec::len(args) < 2u {
+        100u
+    } else {
+        uint::parse_buf(istr::bytes(args[1]), 10u)
+    };
+    for each i in uint::range(0u, 100u) {
+        task::spawn(bind f(n));
+    }
+}
\ No newline at end of file