红黑色-跳跃表-有序链表效率对比

本文通过Go语言实现的红黑树、跳跃表、原生map及自定义排序链表进行性能基准测试。测试结果显示,在插入操作上排序链表表现最佳,而查询操作中红黑树和跳跃表优于原生map。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原贴: https://github.com/cpp2go/rbtree_skiplist_benchmark 

go语言实现,红黑树用的nginx源码,跳跃表用的redis实现,map用go原生,sortlist自己实现,二分查找


go test -test.bench=.*

测试结果:

 RbTreeSkipListMapSortList
New116 ns/op169 ns/op60.1 ns/op0.39 ns/op
Insert1037 ns/op1577 ns/op98.5 ns/op 130 ns/op
Load90.1 ns/op148 ns/op50.2 ns/op91.6 ns/op
range 6600 ns/op7106 ns/op22141 ns/op 352 ns/op
     
     


goos: linux
goarch: amd64
Benchmark_RbTreeNew-16          20000000               116 ns/op
Benchmark_SkipListNew-16        10000000               169 ns/op
Benchmark_MapNew-16             30000000                60.1 ns/op
Benchmark_SortListNew-16        2000000000               0.39 ns/op

Benchmark_RbTreeInsert-16        2000000              1037 ns/op
Benchmark_SkipListInsert-16      1000000              1577 ns/op
Benchmark_MapInsert-16          20000000                98.5 ns/op

Benchmark_SortListInsert-16     10000000               130 ns/op

Benchmark_RbTreeLoad-16         20000000                90.1 ns/op
Benchmark_SkipListLoad-16       10000000               148 ns/op
Benchmark_MapLoad-16            30000000                50.2 ns/op

Benchmark_SortListLoad-16       20000000                91.6 ns/op

Benchmark_RbTreeRange-16          300000              6600 ns/op
Benchmark_SkipListRange-16        200000              7106 ns/op
Benchmark_MapRange-16             100000             22141 ns/op

Benchmark_SortListRange-16       5000000               352 ns/op


原作者结论: insert数量小于10000个时,sortlist查询,插入接近map 遍历远高于map

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值