【问题标题】:Testing purescript functions in jsPerf在 jsPerf 中测试纯脚本函数
【发布时间】:2016-01-12 13:08:07
【问题描述】:

我想比较jsPerf中两个PureScript函数的性能。

我需要做哪些编译,需要在“setup”和每个sn-p box中放入哪些部分?

使用 psc 或纸浆。

【问题讨论】:

  • 您可以像使用任何其他 js 库一样使用 purescript 输出。您能否告诉我们您尝试过的内容并提供您想要进行基准测试的脚本。即使我没有使用它的经验 - 看看 'purescript-benchotron'

标签: purescript jsperf


【解决方案1】:

使用 FFI

因为您指的是 JavaScript 实用程序,所以用 JS 编写测试是最容易的。

您可以在单独的 js 文件中编写性能测试(根据您的测试模块名称命名),并通过 Foreign Function Interface 从 purescript 调用它。

假设你想比较fg函数的性能,代码方案可以用以下模板描述:

-- File PerfTest.purs
module PerfTest where

f :: Args -> Result
f args = ...

g :: Args -> Result
g args = ...

foreign import performanceTestImpl 
  :: forall a. (Unit -> a) -> (Unit -> a) -> Unit

main :: Effect Unit
main =
  pure $ performanceTestImpl (\_ -> f args) (\_ -> g args)
// File PerfTest.js
"use static";

exports.performanceTestImpl =
  function(runF) {
    return function(runG) {
      // run jsPerf tests as you would normally do
    };
  };

这会将performanceTestImpl 实现委托给带有两个回调的JavaScript,它们的性能应该被测量和比较。请注意,您需要传递未计算的 lambda 以延迟计算,因为 PureScript 不像 Haskell 那样惰性。 PureScript 应该负责链接。请注意,这两个文件需要具有匹配的名称并放在同一目录中。

【讨论】:

  • 是的,我知道我是 necrobumping,但这个问题可能会推广到其他类似的实用程序。希望有人会觉得这很有帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多