[−][src]Crate cql_tiny_text
This crate implements various CqlType derivatives for storing String values of up to (and including) 255 chars in a CQL database.
Will allocate 1020 bytes per value linked.
Benchmarks
Benchmarks supplied below are fairly rudimentary (and rounded) and are there to give a rough idea of relative costs.
Full benchmark code can be found in github and can be run with
rustup run nightly cargo bench
, but please be aware that they will allocate ~102MB of disk space. The read_to_stream benchmarks also differ slightly from
other CqlType derivatives as they stream into a Vector, not an Array.
Operation | Chars in String | Database dimensions | Mean time (ns) |
---|---|---|---|
Single point read | 1 | 1 | 2 240 (+/- 185) |
Single point read | 255 | 1 | 2 290 (+/- 350) |
Single point read | 1 | 4 | 11 600 (+/- 2 000) |
Single point read | 255 | 4 | 11 670 (+/- 4 400) |
Single point write | 1 | 1 | 4 070 (+/- 300) |
Single point write | 255 | 1 | 4 180 (+/- 350) |
Single point write | 1 | 4 | 15 100 (+/- 2 200) |
Stream read 1 point | 1 | 1 | 2 300 (+/- 500) |
Stream read 1 point | 255 | 1 | 2 300 (+/- 500) |
Stream read 1 point | 1 | 4 | 11 550 (+/- 2 400) |
Stream read 50 000 points | 1 | 1 | 33 524 000 (+/- 540 000) |
Stream read 50 000 points | 255 | 1 | 33 527 000 (+/- 650 000) |
Stream read 50 000 points | 1 | 4 | 43 082 000 (+/- 867 000) |
Stream read 50 000 points | 255 | 4 | 43 600 000 (+/- 1 787 000) |
Examples
The following creates a 1D database, writes 2 values to it, and then streams them into an array.
const N_VALUES_TO_READ: usize = 3; let base_point = [0]; let value1 = "item one"; let value3 = "شماره ۳"; cql_db::create_db::<TinyText>( DATABASE_LOCATION, &[3] ); cql_db::write_value::<TinyText>( DATABASE_LOCATION, &base_point, value1.to_string() ); cql_db::write_value::<TinyText>( DATABASE_LOCATION, &[base_point[0] + 2], value3.to_string() ); let mut result = Vec::with_capacity(N_VALUES_TO_READ); let mut stream = Cursor::new(Vec::new()); cql_db::read_to_stream::<TinyText>( DATABASE_LOCATION, &mut stream, &base_point, N_VALUES_TO_READ as u64 ); stream.seek(SeekFrom::Start(0)); unpack_stream(&mut stream, N_VALUES_TO_READ, |_, value| { result.push(value) }); assert_eq!(result[0], value1.to_string()); assert_eq!(result[1], String::new()); assert_eq!(result[2], value3.to_string());
Structs
TinyText | Static struct for declaring that you want to work with |
Functions
unpack_stream | Unpacks |