From 85ae29814b80b82456b1810d15cbaab4f6bfea88 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 22 May 2018 17:55:45 -0600 Subject: [PATCH] perf 3 --- Chapter09/Cargo.toml | 8 ++++++++ Chapter09/performance_polynomial3.rs | 25 +++++++++++++++++++++++++ Chapter09/performance_polynomial4.rs | 2 ++ 3 files changed, 35 insertions(+) create mode 100644 Chapter09/performance_polynomial3.rs create mode 100644 Chapter09/performance_polynomial4.rs diff --git a/Chapter09/Cargo.toml b/Chapter09/Cargo.toml index 39b5f1b..6af6578 100644 --- a/Chapter09/Cargo.toml +++ b/Chapter09/Cargo.toml @@ -50,3 +50,11 @@ path = "performance_polynomial1.rs" [[bin]] name = "performance_polynomial2" path = "performance_polynomial2.rs" + +[[bin]] +name = "performance_polynomial3" +path = "performance_polynomial3.rs" + +[[bin]] +name = "performance_polynomial4" +path = "performance_polynomial4.rs" diff --git a/Chapter09/performance_polynomial3.rs b/Chapter09/performance_polynomial3.rs new file mode 100644 index 0000000..40dedfc --- /dev/null +++ b/Chapter09/performance_polynomial3.rs @@ -0,0 +1,25 @@ +fn a(n: u64) { + //Is this O(n)? + for _ in 0..n { + b(n) + } +} + +fn b(n: u64) { + //Is this O(n)? + for _ in 0..n { + c(n) + } +} + +fn c(n: u64) { + //This is O(n)? + for _ in 0..n { + let _ = 1 + 1; + } +} + +fn main() { + //What time complexity is this? + a(1000) +} diff --git a/Chapter09/performance_polynomial4.rs b/Chapter09/performance_polynomial4.rs new file mode 100644 index 0000000..f79c691 --- /dev/null +++ b/Chapter09/performance_polynomial4.rs @@ -0,0 +1,2 @@ +fn main() { +}