Last active
December 20, 2015 09:39
-
-
Save 5kg/6109197 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #include <stdio.h> | |
| int main() | |
| { | |
| int i; | |
| for (i = 0; i < 500000; ++i) { | |
| fprintf(stdout, "this is a test from error"); | |
| } | |
| return 0; | |
| } |
This file contains hidden or 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
| package main | |
| import "fmt" | |
| func main() { | |
| for i := 0; i < 500000; i++ { | |
| fmt.Printf("this is a test from error"); | |
| } | |
| } |
This file contains hidden or 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
| real 0m0.054s | |
| user 0m0.017s | |
| sys 0m0.037s | |
| 0 2500001 12500000 output | |
| real 0m1.861s | |
| user 0m0.230s | |
| sys 0m1.627s | |
| 0 2500001 12500000 output |
This file contains hidden or 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
| #!/bin/bash | |
| gcc c_printf.c -O2 -o c_printf | |
| go build go_printf.go | |
| time ./c_printf > output | |
| wc output | |
| time ./go_printf > output | |
| wc output |
package main
import "fmt"
import "os"
func main() {
for i := 0; i < 500000; i++ {
fmt.Fprintf(os.Stdout, "this is a test from error %d", i);
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The comparable c version should be
include <stdio.h>
int main()
{
int i;
for (i = 0; i < 500000; ++i) {
fprintf(stdout, "this is a test from error %d", i);
fflush(stdout);
}
return 0;
}
Go printf do not have buffer, it will write to fd each time you call it.
If you want to use bufio, refer http://golang.org/pkg/bufio/.