Benchmarks of algorithms for convex min-plus convolutions

Overview

Convex min-plus convolution を実現するアルゴリズムの実行時間を比較します。

やり方

長さ N の convex な Vec<i32> を2本生成して、それらの min-plus convolution を3通りの方法で計算します。

  1. brute: 定義どおり計算します。(Θ (N²))
  2. monotone_minima: いわゆる monotone minima のアルゴリズムで計算します。(Θ (N lg N))
  3. smawk: SMAWK アルゴリズムで計算します。(Θ (N))

Convex なベクターを「ランダムに」生成するとある部分はすべて同じ方法で生成されています。詳しくはコードをご覧いただくとよいのですが、ざっくりいうとたとえば2階差分が一様分布になります。

結果

通常のサイズでの比較(対数スケール)

SMAWK が monotone-minma に勝てなくて悲しい気持ちになっています。

通常のサイズの all-zero ベクターでの比較(対数スケール)

このレポジトリの monotone-minima は all-zero のときに実際に Θ (N lg N) かかるのでそれを試してみたのですが、結果はあまり変わりません。

小さめなベクターでの比較(線形スケール)

Monotone minima は 40 ちょっと、SMAWK は画面外ですがおそらく 120 くらいで逆転しそうに見えます。

とても小さなベクターでの比較(線形スケール)

これくらい違います。

結論

ベンチマークに使った SMAWK アルゴリズムがバグっていないと仮定するならば、monotone minima の高速化目的で競プロで使うメリットはなさそうという結論になってしまいます。(ただし、noshi91 さんのツイートにあるようなメリットはあるようです。)

しかし週刊 spaghetti_source さんによる先行研究によると SMAWK のほうが 1.5 倍程度有利なケースがあるようです。

1 倍なのか 1.5 倍なのかは実装の詳細にかなり依存しそうなのでなんとも言えない感じになりました。

有識者のみなさまにお願い

もし私のためにお手間を割いてくださるならば、次のことを試みてくださると嬉しいです。私の不甲斐ないベンチマークのために SMAWK アルゴリズムさんが今後不当により不遇な扱いを受けてしまうととても心苦しいので、ぜひです。

  • バグ報告
  • monotone minima, SMAWK アルゴリズムの定数倍高速化
  • 何らかの分布を仮定したときの両アルゴリズムの実行時間の振る舞い、特に今回の分布(実装定義で申し訳ありません。)で monotone minima が期待線形時間になるかどうかなどについての示唆

Issue や PR などの際には、お手数をおかけしますが、私が GitHub の通知に気づかないことがあるので、私のツイッターアカウント へもご一報頂けると幸いです。

You might also like...
A suite of benchmarks to test e-graph extraction algorithms

Extraction Gym A suite of benchmarks to test e-graph extraction algorithms. Add your algorithm in src/extract and then add a line in src/main.rs. To r

Examples of cw20 usage, extracted from cw-plus, maintained by the community

CosmWasm Tokens This is a collection of cw20-related contracts extracted from cw-plus. These serve as examples of what is possible to build and as sta

Conway Game of Life plus WebAssembly and basic HTTP Server
Conway Game of Life plus WebAssembly and basic HTTP Server

Conway Game of Life plus WebAssembly and basic HTTP Server How to run First, you have to choose what server do you want to use for hosting the wasm ga

Demo Rust / VueJS+element-plus

rust-vue-demo This project demonstrates the integration of npm/vue into a rust axum web-service. The web-service is self-contained, embedding the webu

A brand-new language server for Typst, plus a VS Code extension

Typst LSP A brand-new language server for Typst. Features Syntax highlighting, error reporting, code completion, and function signature help Compiles

Simple CLI tool to create dummy accounts with referral links to give yourself free Plus.
Simple CLI tool to create dummy accounts with referral links to give yourself free Plus.

Free Duolingo Plus A simple CLI tool to create dummy accounts with referral links to give yourself free Plus (max 24/41 weeks depending on whether you

A mostly drop-in replacement for mercantile written w/ rust, plus several other util(e)ities.

utiles utiles = utils + tiles A mostly drop-in replacement for mercantile written w/ rust, plus several other util(e)ities. Installation pip install u

This repository contains the Rust source code for the algorithms in the textbook Algorithms, 4th Edition

Overview This repository contains the Rust source code for the algorithms in the textbook Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

The Computer Language Benchmarks Game: Rust implementations

The Computer Language Benchmarks Game: Rust implementations This is the version I propose to the The Computer Language Benchmarks Game. For regex-dna,

A more modern http framework benchmarker supporting HTTP/1 and HTTP/2 benchmarks.

rewrk A more modern http framework benchmark utility.

Benchmarks for rust serialization frameworks

Rust serialization benchmark The goal of these benchmarks is to provide thorough and complete benchmarks for various rust serialization frameworks. Th

Benchmarks to read parquet to arrow
Benchmarks to read parquet to arrow

Parquet benchmarks This repository contains a set of benchmarks of different implementations of Parquet (storage format) - Arrow (in-memory format).

A small utility to compare Rust micro-benchmarks.
A small utility to compare Rust micro-benchmarks.

cargo benchcmp A small utility for comparing micro-benchmarks produced by cargo bench. The utility takes as input two sets of micro-benchmarks (one "o

Fastmurmur3 - Fast non-cryptographic hash, with the benchmarks to prove it.

Fastmurmur3 Murmur3 is a fast, non-cryptographic hash function. fastmurmur3 is, in my testing, the fastest implementation of Murmur3. Usage let bytes:

rust channel benchmarks to keep stat of performance of Kanal library in comparison with other competitors.
rust channel benchmarks to keep stat of performance of Kanal library in comparison with other competitors.

Rust Channel Benchmarks This is a highly modified fork of the crossbeam-channel benchmarks. to keep track of Kanal library stats in comparison with ot

Benchmarks of most widely used web frameworks built in rust.
Benchmarks of most widely used web frameworks built in rust.

Rust framework benchmarks Benchmarking utility to test the performance of all the rust web frameworks. Built with rust 🚀 . Demo (Last updated: Thu Ju

cargo-generate template for Criterion benchmarks

Criterion Benchmark Template This is a cargo-generate template for quickly creating benchmarks using the Criterion benchmarking framework. Usage $ car

A collection of comparison-benchmarks for Nova & related Proving systems

Nova benchmarks Here's a list of some of the benchmarks we've been taking to better understand how Nova performs vs other proof systems. Live version:

specs & benchmarks for the ZPrize 3 - High Throughput Signature Verification

Zprize: High Throughput Signature Verification How fast do you think you can verify our ECDSA signatures on Aleo? This year's Zprize is winner-take-al

Owner
Kana Nagata(長田歌菜)
天才でごめんなさい。
Kana Nagata(長田歌菜)
This repository contains the Rust source code for the algorithms in the textbook Algorithms, 4th Edition

Overview This repository contains the Rust source code for the algorithms in the textbook Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

chuan 549 Dec 26, 2022
The Computer Language Benchmarks Game: Rust implementations

The Computer Language Benchmarks Game: Rust implementations This is the version I propose to the The Computer Language Benchmarks Game. For regex-dna,

Guillaume P. 69 Jul 11, 2022
rust channel benchmarks to keep stat of performance of Kanal library in comparison with other competitors.

Rust Channel Benchmarks This is a highly modified fork of the crossbeam-channel benchmarks. to keep track of Kanal library stats in comparison with ot

Khashayar Fereidani 14 Dec 21, 2022
A collection of comparison-benchmarks for Nova & related Proving systems

Nova benchmarks Here's a list of some of the benchmarks we've been taking to better understand how Nova performs vs other proof systems. Live version:

Privacy & Scaling Explorations (formerly known as appliedzkp) 18 Apr 17, 2023
Data structures and algorithms for 3D geometric modeling.

geom3d Data structures and algorithms for 3D geometric modeling. Features: Bezier curve and surface B-Spline curve and surface Spin surface Sweep surf

Junfeng Liu 31 Sep 20, 2022
Repository to learn fractal generation algorithms.

Fractalrs Created this project so I can study Rust while programming fractals! I have always wanted to learn fractal generation. Fractals Fractals are

Luke Dias 4 Jun 10, 2023
A heap allocated runtime for deeply recursive algorithms.

Reblessive A heap allocated runtime for deeply recursive algorithms. Turn your cursed recursive algorithm into a blessed heap allocated structure whic

Mees Delzenne 4 Feb 27, 2024
convolutions-rs is a crate that provides a fast, well-tested convolutions library for machine learning

convolutions-rs convolutions-rs is a crate that provides a fast, well-tested convolutions library for machine learning written entirely in Rust with m

null 10 Jun 28, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
Rust TUI library - Clipping region is a set of min/max x/y values applied to the existing region

TinyBit Clipping region is a set of min/max x/y values applied to the existing region A TUI lib This is not yet production ready T O D O TODO: bugs: T

Togglebit 13 May 3, 2022