Property-based testing (PBT) relies on generators for random test cases, often constructed using embedded domain specific languages, which provide expressive combinators for building and composing generators. The effectiveness of PBT depends critically on the speed of these generators. However, careful measurements show that the generator performance of widely used PBT libraries falls well short of what is possible, due principally to (1) the abstraction overhead of their combinator-heavy style and (2) suboptimal sources of randomness. We characterize, quantify, and address these bottlenecks. To eliminate abstraction overheads, we propose a technique based on multi-stage programming, dubbed Allegro. We apply this technique to leading generator libraries in OCaml and Scala 3, significantly improving performance. To quantify the performance impact of the randomness source, we carry out a controlled experiment, replacing the randomness in the OCaml PBT library with an optimized version. Both interventions exactly preserve the semantics of generators, enabling precise, pointwise comparisons. Together, these improvements find bugs up to $13\times$ faster.
翻译:属性基测试(PBT)依赖生成器生成随机测试用例,这些生成器通常通过内嵌领域特定语言构建,提供富有表达力的组合子来构建和组合生成器。PBT的有效性关键取决于这些生成器的速度。然而,精确测量表明,广泛使用的PBT库的生成器性能远未达到理论可能,主要原因在于:(1)其组合子密集型风格带来的抽象开销;(2)次优的随机性来源。我们描述、量化并解决了这些瓶颈。为消除抽象开销,我们提出一种基于多阶段编程的技术,称为Allegro。我们将该技术应用于OCaml和Scala 3中领先的生成器库,显著提升了性能。为量化随机性来源对性能的影响,我们进行了一项控制实验,将OCaml PBT库中的随机性替换为优化版本。这两种干预方法均精确保持了生成器的语义,从而能够进行精确的逐点比较。综合这些改进,发现缺陷的速度最高可提升$13\times$倍。