是否有任何基准测试将Java 8 Streams与Guava Iterables进行比较?

时间:2015-05-04 07:46:58

标签: java performance java-8 guava

我对Java 8上的Guava感到非常高兴 - 迁移到Streams以获取顺序代码是否有任何性能优势或陷阱?

1 个答案:

答案 0 :(得分:3)

我已经开始a project on GitHub玩这个了。

Streams的初步结果令人惊讶地是积极的 - 对于2014年MacBookAir 1.7Ghz i7上的字符串身份图,Java HotSpot(TM)64位服务器VM(版本25.25-b02,混合模式),代码版本{{3} }


Experiment selection: 
  Benchmark Methods:   [guava, iterate, streams]
  Instruments:   [allocation, runtime]
  User parameters:   {}
  Virtual machines:  [default]
  Selection type:    Full cartesian product

This selection yields 6 experiments.
Trial Report (1 of 6):
  Experiment {instrument=allocation, benchmarkMethod=iterate, vm=default, parameters={}}
  Results:
    bytes(B): min=4072.00, 1st qu.=4072.00, median=4072.00, mean=4072.00, 3rd qu.=4072.00, max=4072.00
    objects: min=3.00, 1st qu.=3.00, median=3.00, mean=3.00, 3rd qu.=3.00, max=3.00
Trial Report (2 of 6):
  Experiment {instrument=allocation, benchmarkMethod=guava, vm=default, parameters={}}
  Results:
    bytes(B): min=15104.00, 1st qu.=15104.00, median=15104.00, mean=15104.00, 3rd qu.=15104.00, max=15104.00
    objects: min=17.00, 1st qu.=17.00, median=17.00, mean=17.00, 3rd qu.=17.00, max=17.00
Trial Report (3 of 6):
  Experiment {instrument=allocation, benchmarkMethod=streams, vm=default, parameters={}}
  Results:
    bytes(B): min=15272.00, 1st qu.=15272.00, median=15272.00, mean=15527.64, 3rd qu.=15432.00, max=17252.80
    objects: min=20.00, 1st qu.=20.00, median=20.00, mean=25.00, 3rd qu.=26.00, max=53.00
Trial Report (4 of 6):
  Experiment {instrument=runtime, benchmarkMethod=guava, vm=default, parameters={}}
  Results:
    runtime(ns): min=13365.32, 1st qu.=13660.61, median=13802.51, mean=13961.91, 3rd qu.=14445.46, max=14715.34
Trial Report (5 of 6):
  Experiment {instrument=runtime, benchmarkMethod=iterate, vm=default, parameters={}}
  Results:
    runtime(ns): min=9952.47, 1st qu.=10892.64, median=11372.35, mean=11243.07, 3rd qu.=11785.48, max=12024.76
Trial Report (6 of 6):
  Experiment {instrument=runtime, benchmarkMethod=streams, vm=default, parameters={}}
  Results:
    runtime(ns): min=10527.26, 1st qu.=11051.70, median=11747.29, mean=11631.15, 3rd qu.=12205.97, max=12581.39
Collected 81 measurements from:
  2 instrument(s)
  2 virtual machine(s)
  3 benchmark(s)

Execution complete: 1.188 min.
Results have been uploaded. View them at: https://microbenchmarks.appspot.com/runs/d2c7f83b-2cfa-4217-ab0b-e8d506eaa85c

我仍然围绕谷歌卡钳,但它似乎表明Streams比Guava更快,并且比直接循环慢得多。