Skip to content

performance of fs::dir_exists #500

@xtimbeau

Description

@xtimbeau

I find a huge performance gap between fs::dir_exist() and base::dir.exists(). Is there a reason for that ?

Here is a reprex:

fs::dir_create("test")

bench::mark(
  base::dir.exists("test"),
  base::file.exists("test"),
  fs::dir_exists("test"),
  fs::file_exists("test"), check = FALSE)
#> # A tibble: 4 × 6
#>   expression                         min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>                    <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 "base::dir.exists(\"test\")"     984ns   1.07µs   911414.        0B      0  
#> 2 "base::file.exists(\"test\")"   1.07µs   1.19µs   819353.        0B      0  
#> 3 "fs::dir_exists(\"test\")"    398.11µs 412.95µs     2248.    1.06MB     32.1
#> 4 "fs::file_exists(\"test\")"     7.63µs   8.04µs   121029.     3.3KB     24.2

Created on 2025-12-22 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions