zoukankan      html  css  js  c++  java
  • 更快的datetime string to python datetime转换模块 ciso8601

    https://github.com/closeio/ciso8601

    ciso8601 converts ISO 8601 or RFC 3339 date time strings into Python datetime objects.

    Since it's written as a C module, it is much faster than other Python libraries. Tested with Python 2.7, 3.4, 3.5, 3.6, 3.7.

    当然,如果格式固定已知,那么从字符串里拆出指定位数的字符再转化为int也不算太慢

    https://www.peterbe.com/plog/fastest-python-datetime-parser

    def f1(datestr):
        return datetime.datetime.strptime(datestr, '%Y-%m-%dT%H:%M:%S.%fZ')
    
    
    def f2(datestr):
        return ciso8601.parse_datetime(datestr)
    
    
    def f3(datestr):
        return datetime.datetime(
            int(datestr[:4]),
            int(datestr[5:7]),
            int(datestr[8:10]),
            int(datestr[11:13]),
            int(datestr[14:16]),
            int(datestr[17:19]),
        )
    • f1: baseline
    • f2: 13 times faster
    • f3: 6 times faster
  • 相关阅读:
    love 玫瑰花
    正则表达式
    .NET Mvc
    html收藏
    winform问题集锦
    MSDE2000
    Oracle 语法
    PowerDesigner
    Oracle 操作
    文件转换(待完善)
  • 原文地址:https://www.cnblogs.com/yeyong/p/10441507.html
Copyright © 2011-2022 走看看