Skip to content

Instantly share code, notes, and snippets.

@shogo82148
Created April 29, 2017 22:58
Show Gist options
  • Save shogo82148/24b366edc6c2ce97d50fabffe3dd10ed to your computer and use it in GitHub Desktop.
Save shogo82148/24b366edc6c2ce97d50fabffe3dd10ed to your computer and use it in GitHub Desktop.
gochaとstrrandの比較
gochaで/a{1,10}/にマッチする文字列を100万個生成
$ gocha -n 1000000 'a{1,10}' | sort | uniq -c
499715 a
249676 aa
125295 aaa
62576 aaaa
31241 aaaaa
15764 aaaaaa
7809 aaaaaaa
3933 aaaaaaaa
2007 aaaaaaaaa
1984 aaaaaaaaaa
strrandで/a{1,10}/にマッチする文字列を100万個生成
$ go run main.go 'a{1,10}' | sort | uniq -c
99953 a
99977 aa
99594 aaa
99917 aaaa
100370 aaaaa
99904 aaaaaa
100314 aaaaaaa
99901 aaaaaaaa
99818 aaaaaaaaa
100252 aaaaaaaaaa
(雑なパッチを当てた)
diff --git a/cmd/strrand/main.go b/cmd/strrand/main.go
index 06597d0..b771bbb 100644
--- a/cmd/strrand/main.go
+++ b/cmd/strrand/main.go
@@ -14,12 +14,14 @@ func main() {
}
ptn := os.Args[1]
+ for i := 0; i < 1000000; i++ {
str, err := strrand.RandomString(ptn)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Println(str)
+ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment