niklas-heer / speed-comparison

A repo which compares the speed of different programming languages.
https://niklas-heer.github.io/speed-comparison
MIT License
508 stars 79 forks source link

Tightening the screw for R #49

Closed jonocarroll closed 2 years ago

jonocarroll commented 2 years ago

Optimised by avoiding some operations and creating the sequence in a simpler way.

Note: for the curious, this is still producing the Leibniz sequence of the correct size...

rounds <- 10
x <- 1 / seq.int(-2*rounds+1, 2*rounds, by = 4)
length(x) == rounds
#> [1] TRUE
x[rev(order(abs(x)))]
#>  [1]  1.00000000 -0.33333333  0.20000000 -0.14285714  0.11111111 -0.09090909
#>  [7]  0.07692308 -0.06666667  0.05882353 -0.05263158

Credit to @HenrikBengtsson via Twitter.

jonocarroll commented 2 years ago

I thought that would have improved more. Local runs are sub 300ms for me. The vector being created is ~800MB, so perhaps we're seeing the limit of the CI system rather than the language here.

niklas-heer commented 2 years ago

@jonocarroll that is true according to the documentation these are the specs for the CI runner:

Hardware specification for Windows and Linux virtual machines:

  • 2-core CPU (x86_64)
  • 7 GB of RAM
  • 14 GB of SSD space

But I will still merge it. Thank you for your contribution, and it's interesting to see that this repo is being discussed on Twitter 😅