提高fmt.Println的速度 [英] Improve the speed of fmt.Println

查看:75
本文介绍了提高fmt.Println的速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序表,在某些情况下需要打印8 ^ 20行,这需要花费30秒以上的时间,我想知道是否有可能以某种方式将输出缓冲"到os.Stdout并刷新输出.算法的结尾.我尝试将os.Pipe用作os.Stdout,但这并没有提高打印速度.

I have a prgram that on certain occasions needs to print 8^20 lines, which takes upward of 30 seconds, I was wondering if it was possible to somehow "buffer" the output to os.Stdout and flush the output at the end of the algorithm. I've tried using os.Pipe as os.Stdout, but that did not increase the speed of the prints.

是否有一种无需替换fmt.Println()的方法即可实现?

Is there a way to accomplish that without replacing fmt.Println()?

推荐答案

该想法是编译"据说永远不会改变的格式字符串.例如,请参见 https://github.com/larytet/binlog

The idea is to "compile" the format strings which supposedly never change. For example, see https://github.com/larytet/binlog

这篇关于提高fmt.Println的速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆