-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dynamic borrow checking for dereferencing NumPy arrays.
- Loading branch information
1 parent
983514d
commit b945b14
Showing
10 changed files
with
1,024 additions
and
398 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#![feature(test)] | ||
|
||
extern crate test; | ||
use test::{black_box, Bencher}; | ||
|
||
use numpy::PyArray; | ||
use pyo3::Python; | ||
|
||
#[bench] | ||
fn initial_shared_borrow(bencher: &mut Bencher) { | ||
Python::with_gil(|py| { | ||
let array = PyArray::<f64, _>::zeros(py, (1, 2, 3), false); | ||
|
||
bencher.iter(|| { | ||
let array = black_box(array); | ||
|
||
let _shared = array.readonly(); | ||
}); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn additional_shared_borrow(bencher: &mut Bencher) { | ||
Python::with_gil(|py| { | ||
let array = PyArray::<f64, _>::zeros(py, (1, 2, 3), false); | ||
|
||
let _shared = (0..128).map(|_| array.readonly()).collect::<Vec<_>>(); | ||
|
||
bencher.iter(|| { | ||
let array = black_box(array); | ||
|
||
let _shared = array.readonly(); | ||
}); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn exclusive_borrow(bencher: &mut Bencher) { | ||
Python::with_gil(|py| { | ||
let array = PyArray::<f64, _>::zeros(py, (1, 2, 3), false); | ||
|
||
bencher.iter(|| { | ||
let array = black_box(array); | ||
|
||
let _exclusive = array.readwrite(); | ||
}); | ||
}); | ||
} |
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
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
Oops, something went wrong.