1

I'm trying to run microbenchmark on a block of code that generates isochrones (and returns a SpatialPolygonsDataFrame) for a given set of coordinates. However, when I run the code with microbenchmark, it goes on forever. It will not stop. The same code without microbenchmark runs just fine, in under three seconds.

Here's the data:

latlon <- tibble::tribble(
  ~lon,      ~lat,
  -69.64605,  44.56423,
  -68.760845, 44.821497,
  -70.535831, 44.188819
)

Here's the first thing I tried:

isochrone <- microbenchmark( map2(latlon$lon, latlon$lat, 
                  ~ osrmIsochrone(loc = c(.x, .y),
                                  breaks = seq(0, 30, 30) )) %>%
  do.call(what = rbind)
)

Here's the second thing I tried:

microbenchmark(
isochrone <- map2(latlon$lon, latlon$lat, 
                  ~ osrmIsochrone(loc = c(.x, .y),
                                  breaks = seq(0, 30, 30) )) %>%
  do.call(what = rbind)
)

This code works fine, but obviously it doesn't return a benchmark:

isochrone <- map2(latlon$lon, latlon$lat, 
                  ~ osrmIsochrone(loc = c(.x, .y),
                                  breaks = seq(0, 30, 30) )) %>%
  do.call(what = rbind)

I'm not sure it's relevant, but I should note that I'm using an AWS EC2 server to generate the isochrones. I've also tested the same code on a locally running container, and that microbenchmark test also ran forever; without microbenchmark, the code executed flawlessly in under 3 seconds.

LaissezPasser
  • 396
  • 3
  • 18
  • 3
    I find it suspect that any mortal being can confidently state that something persists forever in the literal sense. With that said, `microbenchmark()` runs the code multiple times to collect statistics. If you set `times=1` inside `microbenchmark()`, you will see that your code completes fine. It's possible that the server limits the number of frequent queries, which causes a delay while `microbenchmark()` iterations wait for a response. – Artem Sokolov Jul 24 '19 at 15:49

1 Answers1

1

As pointed out by Artem Sokolov, adding the argument times=1 fixed it:

microbenchmark(
isochrone <- map2(latlon$lon, latlon$lat, 
                  ~ osrmIsochrone(loc = c(.x, .y),
                                  breaks = seq(0, 30, 30) )) %>%
  do.call(what = rbind)
)
LaissezPasser
  • 396
  • 3
  • 18