【发布时间】:2019-07-25 00:07:49
【问题描述】:
我正在尝试在一个代码块上运行微基准测试,该代码块为给定的一组坐标生成等时线(并返回 SpatialPolygonsDataFrame)。但是,当我使用 microbenchmark 运行代码时,它会一直运行下去。它不会停下来。没有 microbenchmark 的相同代码在三秒内运行良好。
这是数据:
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)
我不确定它是否相关,但我应该注意我正在使用 AWS EC2 服务器来生成等时线。我还在本地运行的容器上测试了相同的代码,并且该微基准测试也一直运行;没有微基准,代码在 3 秒内完美执行。
【问题讨论】:
-
我怀疑任何凡人都可以自信地声明某种事物在字面意义上永远存在。话虽如此,
microbenchmark()多次运行代码以收集统计信息。如果你在microbenchmark()中设置times=1,你会看到你的代码完成得很好。可能是服务器限制了频繁查询的数量,导致microbenchmark()迭代等待响应时出现延迟。
标签: r microbenchmark osrm