-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
verdict from the bench: taking stock is free, updating is ruinous
The word upstream is that the unstable builtin benchmark tests are likely to be deprecated (rust-lang/rust#29553), but I didn't feel like learning Criterion just for this. test inference::triangle::tests::concerning_the_expense_of_computing_entropy ... bench: 0 ns/iter (+/- 0) test inference::triangle::tests::concerning_the_expense_of_updating ... bench: 1,485,967 ns/iter (+/- 81,055) I'm not sure how to interpret the zero for computing the entropy; I assume some sort of clever LLVM optimization has sloughed off the work to compile time. But yeah, that 1.5 million nanoseconds to do an update is way too explosive for a hotspot like `value_of_information`. We're going to need some new techniques.
- Loading branch information
1 parent
5ee5941
commit 877512d
Showing
4 changed files
with
35 additions
and
10 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 |
---|---|---|
|
@@ -156,7 +156,10 @@ pub fn complexity_prior(basic_hypotheses: Vec<BasicHypothesis>) | |
|
||
#[cfg(test)] | ||
mod tests { | ||
use test::Bencher; | ||
|
||
use super::*; | ||
use play::triangle::our_basic_hypotheses; | ||
use triangles::{Color, Size, Stack, Study, Triangle}; | ||
use inference::triangle::hypotheses::{BasicHypothesis, JoinedHypothesis}; | ||
use inference::triangle::hypotheses::color_count_boundedness::ColorCountBoundednessHypothesis; | ||
|
@@ -234,4 +237,20 @@ mod tests { | |
Color::Red, 1))))); | ||
} | ||
|
||
#[bench] | ||
fn concerning_the_expense_of_updating(bencher: &mut Bencher) { | ||
let distribution = complexity_prior(our_basic_hypotheses()); | ||
bencher.iter(|| { | ||
distribution.updated(&Study::sample(), true); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn concerning_the_expense_of_computing_entropy(bencher: &mut Bencher) { | ||
let distribution = complexity_prior(our_basic_hypotheses()); | ||
bencher.iter(|| { | ||
distribution.entropy(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
zackmdavis
Author
Owner
|
||
}); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
mod number; | ||
mod triangle; | ||
pub mod triangle; | ||
|
||
|
||
use argparse::{ArgumentParser, Store, StoreTrue}; | ||
|
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
Remove the
;
. It takes0 ns
to run this because the optimizer realizes that this is a pure fn and you don't use the result, so it just deletes it. Returning the result will cause the optimizer to not do so.(Yes, I checked
master
and this is still there.)https://doc.rust-lang.org/1.12.1/book/benchmark-tests.html#gotcha-optimizations