Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance Groovy I/O性能问题_Performance_Groovy - Fatal编程技术网

Performance Groovy I/O性能问题

Performance Groovy I/O性能问题,performance,groovy,Performance,Groovy,我不是一个groovy专家,只是偶尔使用它。最新的目标之一是生成一个包含一些随机数据的非常简单的文件。我创建了以下脚本: 你知道如何提高groovy的处理速度吗?左移位操作符打开文件,跳到末尾,追加文本,然后再次关闭文件 相反,请尝试: Random random = new Random(); // Open the file and append to it. // If you want a new file each time, use withWriter instead of w

我不是一个groovy专家,只是偶尔使用它。最新的目标之一是生成一个包含一些随机数据的非常简单的文件。我创建了以下脚本:


你知道如何提高groovy的处理速度吗?

左移位操作符打开文件,跳到末尾,追加文本,然后再次关闭文件

相反,请尝试:

Random random = new Random();

// Open the file and append to it.
// If you want a new file each time, use withWriter instead of withWriterAppend
new File('sampledata.txt').withWriterAppend { w ->
  100000.times {
    w.writeLine "${new Date().format('yyyMMdd HH:mm:ss.SSS')}|box|process|||java.lang.Long|${random.nextInt(100)}|name"
  }
}
(这也更像Ruby代码正在做的事情)

File.open("output.txt", "w") do |file|
  100000.times do 
    line = Time.now.strftime("%Y%m%d %H:%M:%S.%L") + '|box|process|||java.lang.Long|' + rand(100).to_s + '|name'
    file.puts line
  end
end
Random random = new Random();

// Open the file and append to it.
// If you want a new file each time, use withWriter instead of withWriterAppend
new File('sampledata.txt').withWriterAppend { w ->
  100000.times {
    w.writeLine "${new Date().format('yyyMMdd HH:mm:ss.SSS')}|box|process|||java.lang.Long|${random.nextInt(100)}|name"
  }
}