# 概要 ## 処理 - (a) コマンドライン引数の1番目を数字に変換 - (b) 0から`(a)`までのイテレートできるものを作成 - (c) `(b)`をすべて2倍し、33333で割り切れるもののみを残して、それぞれを10000で割り、それらすべてを足し合わせる ## 計測 - [[PowerShellでbashのtimeみたいに実行時間を計測]]する方法を使う - 3回測定した平均を採用する - 1回目と2回目で差が大きい場合は、2回目~4回目の平均 # 結果 ## [[Rust]] ```rust fn main() { let args: Vec<String> = std::env::args().skip(1).collect(); let max: i32 = args.first().unwrap().parse().unwrap(); let seeds = 0..=max; let results: i32 = seeds .map(|x| x * 2) .filter(|x| x % 33333 == 0) .map(|x| x / 10000) .sum(); eprintln!("results = {:?}", results); } ``` ```powershell # debug版 Measure-Command { cargo run -- 100000000 } # release版 Measure-Command { target/release/performance.exe 100000000 } ``` | モード | 結果(ms) | | ------- | -------- | | debug | 1925ms | | release | 62ms | ## [[Python]] ```python import sys def main(): args = sys.argv[1:] max = int(args[0]) seeds = range(0, max) results = int(sum(b / 10000 for b in (a * 2 for a in seeds) if b % 33333 == 0)) print(f"results = {results}") if __name__ == "__main__": main() ``` ```powershell Measure-Command { python main.py 100000000 } ``` | バージョン | 結果(ms) | | ---------- | -------- | | 3.11 | 5580ms | | 3.7 | 6310ms | ## [[TypeScript]] ([[Node.js]]) ```ts function main() { const args = process.argv.slice(2); const max = Number(args[0]); const seeds = [...Array(max).keys()]; const results = seeds .map((x) => x * 2) .filter((x) => x % 33333 === 0) .map((x) => x / 10000) .reduce((a, x) => a + x); console.log(`results = ${results}`); } main(); ``` ```ts npm run build Measure-Command { node lib/index.js 100000000 } ``` | [[Node.js]]バージョン | [[TypeScript]]バージョン | 結果(ms) | | --------------------- | ------------------------ | -------- | | v18.12.1 | 5.0.2 | 3938ms |