This file contains hidden or 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
My measurements for the "kernel interrupt timing" programs: | |
|--------------------+-----------------+-------------+------------------------------| | |
| SIGALRM Interval | Program version | Measured Hz | Measured Interval Avg (usec) | | |
|--------------------+-----------------+-------------+------------------------------| | |
| (init setting) 250 | Rust | 4001 | 250 | | |
| (init setting) 250 | C | 4016 | 249 | | |
|--------------------+-----------------+-------------+------------------------------| | |
| 500 | Rust | 2001 | 500 | | |
| 500 | C | 2004 | 499 | |
This file contains hidden or 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
fn double(a: int) -> int { a * 2 } | |
fn ntimes(f: proc(int) -> int, times: int) -> proc(int) -> int { | |
proc(x: int) { | |
match times { | |
0 => { x }, | |
_ => { f(ntimes(f, times - 1)(x)) } // swap the order relative to the original example | |
} | |
} | |
} |
This file contains hidden or 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
use std::io::File; | |
use std::str; | |
fn main() { | |
let file_name_abs = ~"foo"; | |
let mut response =~ ""; | |
match File::open(&Path::new(file_name_abs)) { | |
Some(html_file) => { | |
let mut html_file_mut = html_file; |
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"runtime" | |
) | |
func whisper(left, right chan int) { | |
left <- 1 + <- right | |
} |
This file contains hidden or 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
use std::sync::atomics::AtomicBool; | |
use std::sync::atomics::Ordering; | |
// error unresolved import: there is no `Relaxed` in `std::sync::atomics::Ordering` | |
// use std::sync::atomics::Ordering::Relaxed; | |
fn main() { | |
let mut ab = AtomicBool::new(false); | |
let val1 = ab.load(Ordering::Relaxed); // error: unresolved import: | |
// there is no `Relaxed` in `std::sync::atomics::Ordering` |
This file contains hidden or 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
// | |
// Trying to learn closures/procs in Rust | |
// Want to capture a variable whose private state I can mutate | |
// | |
fn main() { | |
fn call_proc(b: proc(u64) -> u64) { | |
let x = b(10u64); | |
println!("{:?}", x); | |
} | |
This file contains hidden or 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
static N:int = 100000; | |
// | |
// Chinese Whispers in Rust | |
// Based on example by Rob Pike | |
// in http://www.youtube.com/watch?v=f6kdp27TYZs | |
// | |
fn main() { | |
let (leftmost_port, leftmost_chan) = Chan::new(); | |
let mut leftc: Chan<int> = leftmost_chan; |
This file contains hidden or 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
package main | |
import "fmt" | |
// | |
// Chinese Whispers example by Rob Pike | |
// See http://www.youtube.com/watch?v=f6kdp27TYZs | |
// | |
func whisper(left, right chan int) { | |
left <- 1 + <- right |
This file contains hidden or 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
use std::run; | |
use std::str; | |
fn main() { | |
let options = run::ProcessOptions::new(); | |
let process = run::Process::new("fuser", &[~"-m", ~"/media/truecrypt3"], options); | |
match process { | |
Some(mut p) => { | |
let outdata = p.finish_with_output(); | |
let outtxt = str::from_utf8(outdata.output); |
This file contains hidden or 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
fn main() { | |
let mut mon1: ~Sleestak = ~Monster::new(); | |
let mut mon2: ~Reaver = ~Monster::new(); | |
let mut monsters = [mon1 as ~Monster, mon2 as ~Monster]; | |
println!("{:?}", monsters); | |
println("------------------------------"); | |
// attempt 1: fail | |
for m in monsters.iter() { |