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
| """A quick benchmark comparing how quickly `__init__` with default values runs | |
| for various dataclass-like libraries. | |
| We also compare against the time it takes to initialize a `dict` or `tuple` | |
| with the same data, as a "low-bar" for pure-python implementations. | |
| """ | |
| import timeit | |
| import attrs |
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
| #![feature(conservative_impl_trait)] | |
| fn take<'a>(take: &'a str) -> impl Fn(&'a str) -> (&'a str, &'a str) { | |
| move |input| { | |
| let len = input.chars().zip(take.chars()).take_while(|&(i, t)| i == t).count(); | |
| (&input[0..len], &input[len..]) | |
| } | |
| } | |
| fn chain<'a, F1, F2>(first: F1, second: F2) -> impl Fn(&'a str) -> ((&'a str, &'a str), &'a str) |