Go语言中文网 为您找到相关结果 4

golang对象序列化和反序列化

模拟测试1,000, 000条数据 每条10个字节 也就是10M不到的 数据(高度结构化的数据) 过程 1.对象序列化为 byte 2.byte反序为对象 3.gzip压缩byte 测试语言go测试方案: raw byte,json ,bson, msgpack (protostuff需要先做对象配置文件,比较麻烦,通常认为和msgpack性能相当 )结果:msgpack 胜出 大小 gzip压缩后大小 对象到byte耗时 byte到对象耗时 raw 10000000 6573252(65%) 未测试 未测试 json 47515988 7919511 (17%) 3248ms 5280ms bson 49888910 9506965 (19%) 3863ms 6235ms msgpack ...阅读全文

博文 2014-10-04 19:27:16 咖啡伴侣

golang sort 包使用,及三个简单排序算法冒泡,插入,选择 练习

sort 包的核心类型是 sort.Interface: type Interface interface { // Len is the number of elements in the collection. Len() int // Less reports whether the element with // index i should sort before the element with index j. Less(i, j int) bool // Swap swaps the elements with indexes i and j. Swap(i, j int) } 接口 是golang 的很cool 的特性,rob pike 说接口有点类似uinx pipe,把...阅读全文

博文 2015-01-22 17:00:11 yujian0231

【golang基础】socks编程相关的知识点

最近尝试自己用go实现了ss,涉及到socks相关api,这里总结一下socks编程中需要注意的知识点。 socks五元组:src_ip源ip src_port源端口 dst_ip目标ip dst_port目标端口 protocol传输协议(tcp/udp),这五个中任意一个不同就属于不同的socks,不会冲突 从上一条可知,tcp和udp可以使用同一个端口互不影响,因为protocol不同 go语言中listen和dial的src_port必须是不同的端口,否则会报错 read会阻塞,一直到连接端口或者eof(流结束) 字节序有大端和小端,大端是正序,小端是反序,网络传输一般按照大端序 一次read的数据不一定就是一次write的数据,不要臆想数据包的大小,tcp只保证按顺序送达,数据的界...阅读全文

博文 2018-04-03 15:34:42 wind5o