|
| 1 | +#![feature(allocator_api)] |
| 2 | + |
| 3 | +use { |
| 4 | + criterion::Criterion, |
| 5 | + doublets::{ |
| 6 | + mem::{Alloc, FileMapped}, |
| 7 | + split, unit, Doublets, |
| 8 | + }, |
| 9 | + linkspsql::{benchmark, connect, elapsed, prepare_file, SetupTeardown, BACKGROUND_LINKS}, |
| 10 | + std::{ |
| 11 | + error::Error, |
| 12 | + time::{Duration, Instant}, |
| 13 | + }, |
| 14 | + tokio::runtime::Runtime, |
| 15 | +}; |
| 16 | + |
| 17 | +pub fn create_links(c: &mut Criterion) -> Result<(), Box<dyn Error>> { |
| 18 | + let runtime = Runtime::new()?; |
| 19 | + let mut group = c.benchmark_group("Create"); |
| 20 | + let allocator = std::alloc::Global; |
| 21 | + let united = prepare_file("united.links")?; |
| 22 | + let split_data = prepare_file("split_data.links")?; |
| 23 | + let split_index = prepare_file("split_index.links")?; |
| 24 | + { |
| 25 | + let mut client = runtime.block_on(connect())?; |
| 26 | + let mut background = BACKGROUND_LINKS; |
| 27 | + let _ = client.setup(); |
| 28 | + benchmark! { |
| 29 | + group, |
| 30 | + "PSQL_NonTransaction", |
| 31 | + { |
| 32 | + for _ in 0..1_000 { |
| 33 | + let _ = client.create_point(); |
| 34 | + } |
| 35 | + }, |
| 36 | + { |
| 37 | + for index in (background + 1..=background + 1_000).rev() { |
| 38 | + let _ = client.delete(index); |
| 39 | + } |
| 40 | + background += 1_000; |
| 41 | + } |
| 42 | + } |
| 43 | + let _ = client.teardown(); |
| 44 | + } |
| 45 | + { |
| 46 | + let mut client = runtime.block_on(connect())?; |
| 47 | + let mut background = BACKGROUND_LINKS; |
| 48 | + let mut transaction = client.transaction()?; |
| 49 | + let _ = transaction.setup(); |
| 50 | + let _ = transaction.commit(); |
| 51 | + benchmark! { |
| 52 | + group, |
| 53 | + "PSQL_Transaction", |
| 54 | + let mut transaction = client.transaction().unwrap(), |
| 55 | + { |
| 56 | + for _ in 0..1_000 { |
| 57 | + let _ = transaction.create_point(); |
| 58 | + } |
| 59 | + let _ = transaction.commit(); |
| 60 | + }, |
| 61 | + { |
| 62 | + let mut transaction = client.transaction().unwrap(); |
| 63 | + for index in (background + 1..=background + 1_000).rev() { |
| 64 | + let _ = transaction.delete(index); |
| 65 | + } |
| 66 | + let _ = transaction.commit(); |
| 67 | + background += 1_000; |
| 68 | + } |
| 69 | + } |
| 70 | + let _ = client.transaction()?.teardown(); |
| 71 | + } |
| 72 | + { |
| 73 | + let storage = Alloc::new(allocator); |
| 74 | + let mut links = unit::Store::<usize, _>::new(storage)?; |
| 75 | + let _ = links.setup(); |
| 76 | + benchmark! { |
| 77 | + group, |
| 78 | + "Doublets_United_Volatile", |
| 79 | + { |
| 80 | + for _ in 0..1_000 { |
| 81 | + let _ = links.create_point(); |
| 82 | + } |
| 83 | + }, |
| 84 | + { |
| 85 | + for index in (BACKGROUND_LINKS + 1..=BACKGROUND_LINKS + 1_000).rev() { |
| 86 | + let _ = links.delete(index); |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + let _ = links.teardown(); |
| 91 | + } |
| 92 | + { |
| 93 | + let storage = FileMapped::new(united)?; |
| 94 | + let mut links = unit::Store::<usize, _>::new(storage)?; |
| 95 | + let _ = links.setup(); |
| 96 | + benchmark! { |
| 97 | + group, |
| 98 | + "Doublets_United_NonVolatile", |
| 99 | + { |
| 100 | + for _ in 0..1_000 { |
| 101 | + let _ = links.create_point(); |
| 102 | + } |
| 103 | + }, |
| 104 | + { |
| 105 | + for index in (BACKGROUND_LINKS + 1..=BACKGROUND_LINKS + 1_000).rev() { |
| 106 | + let _ = links.delete(index); |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + let _ = links.teardown(); |
| 111 | + } |
| 112 | + { |
| 113 | + let data = Alloc::new(allocator); |
| 114 | + let index = Alloc::new(allocator); |
| 115 | + let mut links = split::Store::<usize, _, _>::new(data, index)?; |
| 116 | + let _ = links.setup(); |
| 117 | + benchmark! { |
| 118 | + group, |
| 119 | + "Doublets_Split_Volatile", |
| 120 | + { |
| 121 | + for _ in 0..1_000 { |
| 122 | + let _ = links.create_point(); |
| 123 | + } |
| 124 | + }, |
| 125 | + { |
| 126 | + for index in (BACKGROUND_LINKS + 1..=BACKGROUND_LINKS + 1_000).rev() { |
| 127 | + let _ = links.delete(index); |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + let _ = links.teardown(); |
| 132 | + } |
| 133 | + { |
| 134 | + let split_data = FileMapped::new(split_data)?; |
| 135 | + let split_index = FileMapped::new(split_index)?; |
| 136 | + let mut links = split::Store::<usize, _, _>::new(split_data, split_index)?; |
| 137 | + let _ = links.setup(); |
| 138 | + benchmark! { |
| 139 | + group, |
| 140 | + "Doublets_Split_NonVolatile", |
| 141 | + { |
| 142 | + for _ in 0..1_000 { |
| 143 | + let _ = links.create_point(); |
| 144 | + } |
| 145 | + }, |
| 146 | + { |
| 147 | + for index in (BACKGROUND_LINKS + 1..=BACKGROUND_LINKS + 1_000).rev() { |
| 148 | + let _ = links.delete(index); |
| 149 | + } |
| 150 | + } |
| 151 | + } |
| 152 | + let _ = links.teardown(); |
| 153 | + } |
| 154 | + group.finish(); |
| 155 | + Ok(()) |
| 156 | +} |
0 commit comments