Last active
September 1, 2025 08:48
-
-
Save Arkoniak/d93a3741ae4102bf4af1e12f6fcda622 to your computer and use it in GitHub Desktop.
Turso db counter performance
This file contains hidden or 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
| use turso_ext::{register_extension, AggFunc, AggregateDerive, Value}; | |
| register_extension! { | |
| aggregates: { TestCount1a, TestCount1, TestCount2, TestCount3 } | |
| } | |
| #[derive(AggregateDerive)] | |
| struct TestCount1a; | |
| impl AggFunc for TestCount1a { | |
| type State = i64; | |
| type Error = &'static str; | |
| const NAME: &'static str = "test_count1a"; | |
| const ARGS: i32 = 0; | |
| fn step(state: &mut Self::State, args: &[Value]) { | |
| _ = args; | |
| *state += 1; | |
| } | |
| fn finalize(state: Self::State) -> Result<Value, Self::Error> { | |
| Ok(Value::from_integer(state)) | |
| } | |
| } | |
| #[derive(AggregateDerive)] | |
| struct TestCount1; | |
| impl AggFunc for TestCount1 { | |
| type State = i64; | |
| type Error = &'static str; | |
| const NAME: &'static str = "test_count1"; | |
| const ARGS: i32 = 1; | |
| fn step(state: &mut Self::State, args: &[Value]) { | |
| _ = args; | |
| *state += 1; | |
| } | |
| fn finalize(state: Self::State) -> Result<Value, Self::Error> { | |
| Ok(Value::from_integer(state)) | |
| } | |
| } | |
| #[derive(AggregateDerive)] | |
| struct TestCount2; | |
| impl AggFunc for TestCount2 { | |
| type State = i64; | |
| type Error = &'static str; | |
| const NAME: &'static str = "test_count2"; | |
| const ARGS: i32 = 1; | |
| fn step(state: &mut Self::State, args: &[Value]) { | |
| if let Some(x) = args.first().and_then(Value::to_integer) { | |
| _ = x; | |
| *state += 1; | |
| } | |
| } | |
| fn finalize(state: Self::State) -> Result<Value, Self::Error> { | |
| Ok(Value::from_integer(state)) | |
| } | |
| } | |
| #[derive(AggregateDerive)] | |
| struct TestCount3; | |
| impl AggFunc for TestCount3 { | |
| type State = i64; | |
| type Error = &'static str; | |
| const NAME: &'static str = "test_count3"; | |
| const ARGS: i32 = 1; | |
| fn step(state: &mut Self::State, args: &[Value]) { | |
| if let Some(x) = args.first().and_then(Value::to_float) { | |
| _ = x; | |
| *state += 1; | |
| } | |
| } | |
| fn finalize(state: Self::State) -> Result<Value, Self::Error> { | |
| Ok(Value::from_integer(state)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hyperfine measurments