我正在尝试在一个代码块上运行微基准测试,该代码块为给定的一组坐标生成等时线(并返回一个SpatialPolygonsDataFrame)。然而,当我使用微基准测试运行代码时,它永远都在继续。它不会停止。同样的代码在没有微基准的情况下运行良好,不到3秒。
以下是数据:
latlon <- tibble::tribble(
~lon, ~lat,
-69.64605, 44.56423,
-68.760845, 44.821497,
-70.535831, 44.188819
)这是我尝试的第一件事:
isochrone <- microbenchmark( map2(latlon$lon, latlon$lat,
~ osrmIsochrone(loc = c(.x, .y),
breaks = seq(0, 30, 30) )) %>%
do.call(what = rbind)
)这是我尝试的第二件事:
microbenchmark(
isochrone <- map2(latlon$lon, latlon$lat,
~ osrmIsochrone(loc = c(.x, .y),
breaks = seq(0, 30, 30) )) %>%
do.call(what = rbind)
)这段代码运行良好,但显然它不会返回基准:
isochrone <- map2(latlon$lon, latlon$lat,
~ osrmIsochrone(loc = c(.x, .y),
breaks = seq(0, 30, 30) )) %>%
do.call(what = rbind)我不确定它是否相关,但我应该注意到,我使用的是亚马逊网络服务的EC2服务器来生成等时线。我还在本地运行的容器上测试了相同的代码,该微基准测试也永远运行;如果没有微基准测试,代码将在3秒内完美执行。
发布于 2019-07-25 00:03:52
正如Artem Sokolov所指出的,添加参数times=1修复了这个问题:
microbenchmark(
isochrone <- map2(latlon$lon, latlon$lat,
~ osrmIsochrone(loc = c(.x, .y),
breaks = seq(0, 30, 30) )) %>%
do.call(what = rbind)
)https://stackoverflow.com/questions/57186579
复制相似问题