Skip to content

Conversation

@m-muecke
Copy link
Contributor

@m-muecke m-muecke commented Apr 9, 2025

Use more concise and performant isTRUE(x)/isFALSE(x)

x <- 1:10
bench::mark(identical(x, TRUE), isTRUE(x))
#> # A tibble: 2 × 6
#>   expression              min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>         <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 identical(x, TRUE)    533ns    615ns  1221275.        0B        0
#> 2 isTRUE(x)              82ns    123ns  6305751.        0B        0
x <- TRUE
bench::mark(identical(x, TRUE), isTRUE(x))
#> # A tibble: 2 × 6
#>   expression              min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>         <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 identical(x, TRUE)    533ns    615ns  1351497.        0B       0 
#> 2 isTRUE(x)             164ns    246ns  3412963.        0B     341.
df <- data.frame(x = rnorm(10), y = rnorm(10))
bench::mark(identical(df, TRUE), isTRUE(df))
#> # A tibble: 2 × 6
#>   expression               min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>          <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 identical(df, TRUE)    533ns    615ns  1526190.        0B        0
#> 2 isTRUE(df)              82ns    123ns  6570761.        0B        0

Created on 2025-04-09 with reprex v2.1.1

@s-fleck
Copy link
Owner

s-fleck commented Apr 11, 2025

Hi! great input, thanks. I actually thought it would be the other way round performance wise... i'll need a bit to review this but i'll merge it in a week or so!

@s-fleck s-fleck merged commit 53a91db into s-fleck:master Apr 14, 2025
1 check passed
@s-fleck
Copy link
Owner

s-fleck commented Apr 14, 2025

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants