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
# Fastest implementation in Crystal, but needs the following lines added to lib_gmp.cr | |
# and recompile the Crystal: | |
# | |
# fun submul_ui = __gmpz_submul_ui(rop : MPZ*, op1 : MPZ*, op2 : ULong) | |
# fun addmul_ui = __gmpz_addmul_ui(rop : MPZ*, op1 : MPZ*, op2 : ULong) | |
# | |
# ...or you could rebind to GMPlib and implement them in your own `lib` and use that | |
# in the #addmul and #submul methods instead if you don't have Crystal source code available. | |
# **SEE VERSION 5 for an implementation of this without changing the stdlib and confirm the perfomance** |
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
fn main() { | |
let mut session = UoW::new(); | |
let entry = session.load::<SomeEntity>(); | |
println!("{:?}", entry); | |
entry.value().msg = "Changed".to_string(); | |
println!("{:?}", entry); | |
let other_entry = session.load::<SomeOtherEntity>(); | |
println!("{:?}", other_entry); |
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
use lazy_static::lazy_static; | |
use rand::random; | |
use std::io::Write; | |
use std::ops::{Add, Mul, Not, Rem}; | |
#[derive(Debug, Clone, Copy)] | |
struct Vec3 { | |
x: f32, | |
y: f32, | |
z: f32, |
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
use lazy_static::lazy_static; | |
use rand::random; | |
use std::io::Write; | |
use std::ops::{Add, Mul, Not, Rem}; | |
#[derive(Debug, Clone, Copy)] | |
struct Vec3 { | |
x: f32, | |
y: f32, | |
z: f32, | |
} |
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
// -------- We change the code from this: -------- | |
lazy_static! { | |
static ref LETTERS: Vec<i32> = { | |
let x: String = [ | |
"5O5_", "5W9W", "5_9_", // P (without curve) | |
"AOEO", "COC_", "A_E_", // I | |
"IOQ_", "I_QO", // X | |
"UOY_", "Y_]O", "WW[W", // A | |
"aOa_", "aWeW", "a_e_", "cWiO" // R (without curve) | |
].concat(); |
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
// -------- Our main function will change from this -------- | |
fn main() { | |
// {...} | |
for y in (0..h as u64).rev() { | |
for x in (0..w as u64).rev() { | |
let mut color = Vec3::from(0.0); | |
for _ in (0..samples_count).rev() { | |
color = color | |
+ trace( | |
position, |
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
// -------- We change the relevant code in main() from this: -------- | |
fn main() { | |
// {...} | |
let bytes: Vec<u8> = pixels.iter().flat_map(|(y, x)| { | |
let mut color = Vec3::from(0.0); | |
for _ in (0..samples_count).rev() { | |
color = color + trace(position, !(goal + left * (*x - w / 2.0 + random_val()).into() + up * (*y - h / 2.0 + random_val()).into())); | |
} | |
color = color * (1.0 / samples_count as f32).into() + (14.0 / 241.0).into(); |
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
// For the sake of brevity I won't repeat the code we replace here instead point out | |
// that this replaces lines 307-328 in our original code example and of course the | |
// lass change we made when introducint Rayon the first time | |
fn main() { | |
// {...} | |
// first we create a range iterator ower | |
let bytes: Vec<u8> = (0..h as u32) | |
// turn it in to a parrallell iterator | |
.into_par_iter() |
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
// For the sake of brevity I won't repeat the code we replace here instead point out | |
// that this replaces lines 307-328 in our original code | |
fn main() { | |
// {...} | |
// first we create a range iterator over y-coordinates | |
let bytes: Vec<u8> = (0..h as u32) | |
// turn it in to a parallel iterator | |
.into_par_iter() |
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
// For the sake of brevity I won't repeat the code we replace here instead point out | |
// that this replaces lines 307-328 in our original code | |
const BYTES_PER_PIXEL: usize = 3; | |
fn main() { | |
// {...} | |
// first allocate a zeroed Vec<u8> to hold our results. | |
// btw: this initialization method is the fastest way to ask | |
// for zeroed memory: see https://github.com/rust-lang/rust/issues/54628 | |
let mut bytes = vec![0u8; h as usize * w as usize * BYTES_PER_PIXEL]; |
OlderNewer