This is a little example program (solves Euler Problem 102):
extern crate smallvec;
fn contains_origin(a: (i32, i32), b: (i32, i32), c: (i32, i32)) -> bool {
let area = a.0 * (b.1 - c.1) + b.0 * (c.1 - a.1) + c.0 * (a.1 - b.1);
let sign = area.signum();
let s = (c.0 * a.1 - a.0 * c.1) * sign;
let t = (a.0 * b.1 - b.0 * a.1) * sign;
s > 0 && t > 0 && area.abs() > s + t
}
fn main() {
use std::fs::File;
use std::io::{BufReader, BufRead};
use smallvec::SmallVec;
let e102 =
BufReader::new(File::open("p102_triangles4096.txt").unwrap())
.lines()
.map(|line| {
let r = line
.unwrap()
.split(',')
.map(|p| p.parse().unwrap())
.collect::<SmallVec<[_; 6]>>();
contains_origin((r[0], r[1]),(r[2], r[3]),(r[4], r[5]))
})
.filter(|&c| c)
.count();
println!("{}", e102);
}
The cargo.toml contains:
[dependencies]
smallvec = "0.1.7"
[profile.release]
opt-level = 3
debug = false
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
If I compile it with:
cargo rustc --release --bin e102 -- -C target-cpu=native
The compilation time is about 3.6 seconds, the binary size is 312 kb,
the run-time is about 1.00 seconds.
If I compile it with:
cargo rustc --release --bin e102 -- -C target-cpu=native -Z orbit
The compilation time is about 3.9 seconds, the binary size is 314 kb, the run-time is about 1.08 seconds.
The p102_triangles4096.txt file is the concatenation of 4096 copies of the p102_triangles.txt file in the Euler problem 102:
https://projecteuler.net/project/resources/p102_triangles.txt
https://projecteuler.net/problem=102
So in this case with -Z orbit the compilation time is bigger, the binary is bigger and the run-time is bigger.