Created
July 27, 2019 05:33
-
-
Save quiye/3eeb58f6d1e0f9285a334981983b8e1e to your computer and use it in GitHub Desktop.
msgpackの練習
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 ( | |
| "log" | |
| "math" | |
| "github.com/vmihailenco/msgpack" | |
| ) | |
| func main() { | |
| for i := 0; i < 10000; i = int(float32(i+1) * 1.7) { | |
| var b string | |
| for j := 0; j < i; j++ { | |
| b = b + "a" | |
| } | |
| f(b) | |
| } | |
| } | |
| func f(s string) { | |
| b, _ := msgpack.Marshal(s) | |
| log.Printf("%#v, %d, %d", b[:int32(math.Min(10, float64(len(b))))], len(b), len(s)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ go run main.go 2019/07/27 05:30:37 []byte{0xa0}, 1, 0 2019/07/27 05:30:37 []byte{0xa1, 0x61}, 2, 1 2019/07/27 05:30:37 []byte{0xa3, 0x61, 0x61, 0x61}, 4, 3 2019/07/27 05:30:37 []byte{0xa6, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61}, 7, 6 2019/07/27 05:30:37 []byte{0xab, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61}, 12, 11 2019/07/27 05:30:37 []byte{0xb4, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61}, 21, 20 2019/07/27 05:30:37 []byte{0xd9, 0x23, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61}, 37, 35 2019/07/27 05:30:37 []byte{0xd9, 0x3d, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61}, 63, 61 2019/07/27 05:30:37 []byte{0xd9, 0x69, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61}, 107, 105 2019/07/27 05:30:37 []byte{0xd9, 0xb4, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61}, 182, 180 2019/07/27 05:30:37 []byte{0xda, 0x1, 0x33, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61}, 310, 307 2019/07/27 05:30:37 []byte{0xda, 0x2, 0xb, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61}, 526, 523 2019/07/27 05:30:37 []byte{0xda, 0x3, 0x7a, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61}, 893, 890 2019/07/27 05:30:37 []byte{0xda, 0x5, 0xea, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61}, 1517, 1514 2019/07/27 05:30:37 []byte{0xda, 0xa, 0xf, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61}, 2578, 2575 2019/07/27 05:30:37 []byte{0xda, 0x11, 0x1b, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61}, 4382, 4379 2019/07/27 05:30:37 []byte{0xda, 0x1d, 0x16, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61}, 7449, 7446https://github.com/msgpack/msgpack/blob/master/spec.md