计算机语言基准测试游戏对于Threadring的F#条目包含一条看似无用的行:if false then ().当我注释掉这一行时,程序运行得更快(对于50000000的输入,~2s vs~55s)并产生相同的结果.这是如何运作的?为什么这条线路在那里?编译器到底做了什么似乎是无操作?
代码:
let ringLength = 503
let cells = Array.zeroCreate ringLength
let threads = Array.zeroCreate ringLength
let answer = ref -1
let createWorker i =
let next = (i+1)%ringLength
async { let value = cells.[i]
if false then ()
match value with
| 0 -> answer := i+1
| _ ->
cells.[next] <- value - 1
return! threads.[next] }
[<EntryPoint>]
let main args =
cells.[0] <- if args.Length>0 then int …Run Code Online (Sandbox Code Playgroud) f# ×1