美文网首页
golang 排序耗时总结

golang 排序耗时总结

作者: 小明2021 | 来源:发表于2023-09-20 10:21 被阅读0次

    golang 排序耗时总结

    总结:

    知道快排速度快,但是没想到这么快,比golang系统自带的排序快了将近一倍
    比选择、插入、冒泡等快了几十上百倍。。。。

    快排:

    「左右指针,往中间靠拢,交换,递归」

    1百万随机数字耗时 0.12 秒左右
    1千万随机数字耗时 1.3 秒左右
    1亿随机数字耗时 15 秒左右

    golang自带sort排序:

    1百万随机数字耗时 0.18 秒左右
    1千万随机数字耗时 2.15 秒左右
    1亿随机数字耗时 24.8 秒左右

    选择排序:

    「每次选出最小的一个,跟外层i比较交互」

    1万随机数字耗时 0.05 秒左右
    5万随机数字耗时 1.28 秒左右
    十万随机数字耗时 5.14 秒左右

    插入排序:

    「每次往前面排序后的数据里一个个比较插入合适的位置」

    1万随机数字耗时 0.08 秒左右
    5万随机数字耗时 1.94 秒左右
    十万随机数字耗时 7.8 秒左右

    冒泡排序:

    1万随机数字耗时 0.06 秒左右
    5万随机数字耗时 2.35 秒左右
    十万随机数字耗时 9.51 秒左右

    相关文章

      网友评论

          本文标题:golang 排序耗时总结

          本文链接:https://www.haomeiwen.com/subject/qygovdtx.html