tree_cache.rs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2022 The Matrix.org Foundation C.I.C.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #![feature(test)]
  15. use synapse::tree_cache::TreeCache;
  16. use test::Bencher;
  17. extern crate test;
  18. #[bench]
  19. fn bench_tree_cache_get_non_empty(b: &mut Bencher) {
  20. let mut cache: TreeCache<&str, &str> = TreeCache::new();
  21. cache.set(["a", "b", "c", "d"], "f").unwrap();
  22. b.iter(|| cache.get(&["a", "b", "c", "d"]));
  23. }
  24. #[bench]
  25. fn bench_tree_cache_get_empty(b: &mut Bencher) {
  26. let cache: TreeCache<&str, &str> = TreeCache::new();
  27. b.iter(|| cache.get(&["a", "b", "c", "d"]));
  28. }
  29. #[bench]
  30. fn bench_tree_cache_set(b: &mut Bencher) {
  31. let mut cache: TreeCache<&str, &str> = TreeCache::new();
  32. b.iter(|| cache.set(["a", "b", "c", "d"], "f").unwrap());
  33. }
  34. #[bench]
  35. fn bench_tree_cache_length(b: &mut Bencher) {
  36. let mut cache: TreeCache<u32, u32> = TreeCache::new();
  37. for c1 in 0..=10 {
  38. for c2 in 0..=10 {
  39. for c3 in 0..=10 {
  40. for c4 in 0..=10 {
  41. cache.set([c1, c2, c3, c4], 1).unwrap()
  42. }
  43. }
  44. }
  45. }
  46. b.iter(|| cache.len());
  47. }