小编Asc*_*hen的帖子

Crystal 中的 Int32 与 Float64 性能

我运行了这个基准测试,我很惊讶地发现,对于 Int32 或 Float64 操作,Crystal 性能几乎相同。

$ crystal benchmarks/int_vs_float.cr --release
  int32 414.96M (  2.41ns) (±14.81%)  0.0B/op        fastest
float64 354.27M (  2.82ns) (±12.46%)  0.0B/op   1.17× slower
Run Code Online (Sandbox Code Playgroud)

我的基准代码是否有一些奇怪的副作用?

require "benchmark"

res = 0
res2 = 0.0

Benchmark.ips do |x|
  x.report("int32") do
    a = 128973 / 119236
    b = 119236 - 128973

    d = 117232 > 123462 ? 117232 * 123462 : 123462 / 117232

    res = a + b + d
  end

  x.report("float64") do
    a = 1.28973 / 1.19236
    b = 1.19236 …
Run Code Online (Sandbox Code Playgroud)

performance crystal-lang

2
推荐指数
1
解决办法
96
查看次数

标签 统计

crystal-lang ×1

performance ×1