11import re
2- import typing as t
32
43# this regex is based on the one from the rfc3339-validator package
54# credit to the original author
5655)
5756
5857
59- def validate (date_str : t . Any ) -> bool :
58+ def validate (date_str : object ) -> bool :
6059 """Validate a string as a RFC3339 date-time."""
6160 if not isinstance (date_str , str ):
6261 return False
@@ -80,18 +79,15 @@ def validate(date_str: t.Any) -> bool:
8079 import timeit
8180
8281 N = 100_000
83- long_fracsec = "2018-12-31T23:59:59.8446519776713Z"
84- basic = "2018-12-31T23:59:59Z"
85- in_february = "2018-02-12T23:59:59Z"
86- in_february_invalid = "2018-02-29T23:59:59Z"
82+ tests = (
83+ ("long_fracsec" , "2018-12-31T23:59:59.8446519776713Z" ),
84+ ("basic" , "2018-12-31T23:59:59Z" ),
85+ ("in_february" , "2018-02-12T23:59:59Z" ),
86+ ("in_february_invalid" , "2018-02-29T23:59:59Z" ),
87+ )
8788
8889 print ("benchmarking" )
89- for name , val in (
90- ("long_fracsec" , long_fracsec ),
91- ("basic" , basic ),
92- ("february" , in_february ),
93- ("february_invalid" , in_february_invalid ),
94- ):
90+ for name , val in tests :
9591 all_times = timeit .repeat (
9692 f"validate({ val !r} )" , globals = globals (), repeat = 3 , number = N
9793 )
0 commit comments