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
// BSD 3-Clause License | |
// | |
// Copyright (c) 2017, 0qdk4o | |
// All rights reserved. | |
// | |
// Redistribution and use in source and binary forms, with or without | |
// modification, are permitted provided that the following conditions are met: | |
// | |
// * Redistributions of source code must retain the above copyright notice, this | |
// list of conditions and the following disclaimer. |
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
// 有四个线程1、2、3、4。线程1的功能就是输出1,线程2的功能就是输出2,以此类推......... | |
// 现在有四个文件ABCD。初始都为空。现要让四个文件呈如下格式: | |
// A:1 2 3 4 1 2.... | |
// B:2 3 4 1 2 3.... | |
// C:3 4 1 2 3 4.... | |
// D:4 1 2 3 4 1.... | |
// 没必要用chan chan的切换代价是很大的 我一般能不用就不用,观察规律好像这样也可以生成目标文件 | |
// 并且是用四个coroutine 写文件可以先写缓冲区再一次写4K或16K 这样会更高效 但这并不是本问题重点 |
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
首先参考 http://herman.asia/efficient-string-concatenation-in-go | |
另外补充: 连接效率,内存使用率还与所连接字符串长度本身是有影响的 | |
与本机核数多少依然有影响 | |
以下测试均在go version go1.9 | |
func BenchmarkBuffer(b *testing.B) { | |
b.ReportAllocs() | |
b.ResetTimer() |