Last active
August 29, 2015 14:06
-
-
Save yanhua365/5949cdd1be22aa3ce4e0 to your computer and use it in GitHub Desktop.
使用groovy和gbench对文件操作的两种方式(append和writer)进行基准测试(来自:https://stackoverflow.com/questions/23552282/groovy-file-append-vs-file-newwriter)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group='org.gperfutils', module='gbench', version='0.4.2-groovy-2.1') | |
def b = benchmark { | |
'append' { | |
def f = File.createTempFile('file', 'append') | |
(1..1000).each { | |
f.append(it.toString()) | |
} | |
} | |
'writer' { | |
def f = File.createTempFile('file', 'writer') | |
def w = f.withWriter{w-> | |
(1..1000).each { | |
w.write(it.toString()) | |
} | |
} | |
} | |
} | |
b.prettyPrint( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Environment | |
=========== | |
* Groovy: 2.2.1 | |
* JVM: Java HotSpot(TM) 64-Bit Server VM (24.45-b08, Oracle Corporation) | |
* JRE: 1.7.0_45 | |
* Total Memory: 103.5 MB | |
* Maximum Memory: 114 MB | |
* OS: Windows 8 (6.2, amd64) | |
Options | |
======= | |
* Warm Up: Auto (- 60 sec) | |
* CPU Time Measurement: On | |
user system cpu real | |
append 26028989 343758049 369787038 398199984 | |
writer 395846 1425295 1821141 1960860 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment