Skip to content

Instantly share code, notes, and snippets.

@dvu4
Created December 16, 2022 17:53
Show Gist options
  • Save dvu4/d4268cfbbd40616357390691cb6783d8 to your computer and use it in GitHub Desktop.
Save dvu4/d4268cfbbd40616357390691cb6783d8 to your computer and use it in GitHub Desktop.
This script compares running time between "datetime.timedelta", "dateutil.relativedelta.relativedelta" and maya.add() when working only with days and compare 2 dates with 3 different approaches
import datetime
from dateutil.relativedelta import *
import maya
from dateutil import parser
import timeit
test = ['2023-01-15T20:56:24Z', '2023-12-15T14:47:33.049Z', '2023-01-21T15:28:50Z', '2023-01-21T15:29:33Z',
'2023-01-21T15:29:40Z', '2023-01-21T15:29:47Z', '2023-01-21T15:29:54Z', '2023-01-25T09:51:44Z',
'2023-01-25T09:51:51Z', '2023-01-25T09:51:57Z', '2023-01-31T14:05:43Z', '2023-01-31T14:05:48Z',
'2023-01-31T14:05:54Z', '2023-01-31T14:06:01Z', '2023-02-03T14:41:42Z', '2023-02-10T13:05:57Z',
'2023-02-10T13:06:03Z', '2023-02-10T13:06:09Z', '2023-02-10T16:09:07Z', '2023-02-16T15:02:52Z',
'2023-02-16T15:02:59Z', '2023-02-16T15:04:26Z', '2023-02-20T17:50:40Z', '2023-02-20T17:50:47Z',
'2023-02-21T15:17:04Z', '2023-02-21T15:17:11Z', '2023-07-26T12:27:51Z', '2023-02-21T20:58:12Z',
'2023-02-21T20:58:19Z', '2023-02-23T13:02:08Z', '2023-02-23T13:02:15Z', '2023-02-23T13:02:22Z',
'2023-02-25T11:20:26Z', '2023-03-02T15:25:56Z', '2023-03-02T15:26:06Z', '2023-03-02T15:26:14Z',
'2023-03-13T12:56:02Z', '2023-03-17T14:00:47Z', '2023-04-12T11:20:02Z', '2023-03-17T20:22:21Z',
'2023-03-22T19:57:45Z', '2023-03-22T20:01:11Z', '2023-03-22T20:01:18Z', '2023-03-22T20:01:24Z',
'2023-03-22T20:01:29Z', '2023-03-22T20:01:35Z', '2023-03-22T20:01:41Z', '2023-03-22T20:01:47Z',
'2023-03-22T20:01:52Z', '2023-03-22T20:01:58Z', '2023-03-22T20:02:04Z', '2023-03-22T20:02:10Z',
'2023-03-22T20:02:15Z', '2023-03-22T20:02:21Z', '2023-03-22T20:02:27Z', '2023-03-22T20:02:33Z',
'2023-03-22T20:02:40Z', '2023-03-22T20:02:45Z', '2023-03-22T20:02:51Z', '2023-03-22T20:02:57Z',
'2023-03-22T20:03:03Z', '2023-03-22T20:03:08Z', '2023-03-22T20:03:14Z', '2023-03-22T20:03:20Z',
'2023-03-22T20:03:26Z', '2023-03-22T20:03:31Z', '2023-03-22T20:03:37Z', '2023-03-22T20:03:44Z',
'2023-03-22T20:03:49Z', '2023-03-22T20:03:54Z', '2023-03-22T20:04:00Z', '2023-03-22T20:04:06Z',
'2023-03-22T20:04:11Z', '2023-03-22T20:04:16Z', '2023-03-22T20:04:22Z', '2023-03-22T20:04:27Z',
'2023-03-22T20:04:32Z', '2023-03-22T20:04:38Z', '2023-03-22T20:04:45Z', '2023-03-22T20:04:50Z',
'2023-03-22T20:04:56Z', '2023-09-12T16:18:04Z', '2023-09-12T16:20:32Z', '2023-09-12T16:16:36Z',
'2023-03-30T19:45:46Z', '2023-03-30T19:45:55Z', '2023-04-12T11:48:10Z', '2023-04-12T12:08:24Z',
'2023-04-15T13:36:59Z', '2023-04-15T13:39:21Z', '2023-04-15T13:39:29Z', '2023-04-15T13:39:46Z',
'2023-04-15T13:39:53Z', '2023-04-15T13:40:01Z', '2023-04-15T13:40:08Z', '2023-04-15T13:40:16Z',
'2023-04-15T13:40:23Z', '2023-04-18T15:06:41Z', '2023-04-18T15:06:49Z', '2023-05-04T10:32:01Z',
'2023-05-04T10:32:08Z', '2023-05-04T10:32:15Z', '2023-05-12T15:50:51Z', '2023-05-12T15:50:59Z',
'2023-05-12T15:51:08Z', '2023-05-13T11:05:51Z', '2023-05-13T11:06:00Z', '2023-05-13T11:06:08Z',
'2023-05-18T17:23:05Z', '2023-05-18T17:23:11Z', '2023-05-18T17:23:17Z', '2023-05-19T16:16:24Z',
'2023-05-19T16:16:32Z', '2023-05-19T16:16:39Z', '2023-05-19T16:48:51Z', '2023-05-19T16:48:59Z',
'2023-05-19T16:49:05Z', '2023-05-26T15:22:20Z', '2023-05-26T15:22:28Z', '2023-05-26T15:32:54Z',
'2023-06-01T12:46:54Z', '2023-07-12T14:33:26Z', '2023-07-12T14:33:37Z', '2023-07-12T14:33:48Z',
'2023-07-22T11:08:34Z', '2023-07-23T16:46:54Z', '2023-07-24T03:47:49Z', '2023-08-18T13:10:59Z',
'2023-08-10T17:15:23Z', '2023-09-14T00:24:06Z', '2023-09-14T00:22:52Z', '2023-09-14T00:23:45Z',
'2023-09-14T00:23:52Z', '2023-09-14T00:23:59Z', '2023-09-14T00:24:15Z', '2023-09-14T00:24:23Z',
'2023-09-14T00:24:30Z', '2023-09-14T00:24:44Z', '2023-09-14T00:24:52Z', '2023-09-14T00:24:59Z',
'2023-09-14T00:25:14Z', '2023-09-14T00:25:07Z', '2023-09-14T00:26:00Z', '2023-09-14T00:25:53Z',
'2023-09-14T00:25:32Z', '2023-09-14T00:25:46Z', '2023-09-14T00:26:13Z', '2023-09-14T00:26:06Z',
'2023-09-14T00:26:27Z', '2023-09-14T00:26:34Z', '2023-09-14T00:26:20Z', '2023-09-14T00:26:41Z',
'2023-09-14T00:26:54Z', '2023-09-14T00:26:48Z', '2023-09-14T00:27:15Z', '2023-09-14T00:24:37Z',
'2023-09-14T00:27:02Z', '2023-09-14T00:25:39Z', '2023-09-14T00:27:08Z', '2023-08-29T16:00:53Z',
'2023-08-29T20:08:29Z', '2023-09-02T14:39:23Z', '2023-09-02T14:39:32Z', '2023-09-12T18:51:14Z',
'2023-09-12T16:29:30Z', '2023-09-13T15:00:49Z', '2023-09-14T00:23:37Z', '2023-09-14T00:25:25Z',
'2023-09-14T19:09:12Z', '2023-09-14T19:09:50Z', '2023-09-14T19:19:44Z', '2023-09-26T17:42:19Z',
'2023-09-26T22:11:13Z', '2023-09-26T22:11:23Z', '2023-09-26T22:11:33Z', '2023-09-26T22:13:57Z',
'2023-09-28T16:53:03Z', '2023-01-13T16:18:57Z', '2023-10-05T13:41:05Z', '2023-10-07T15:35:22Z',
'2023-10-07T15:36:43Z', '2023-10-12T15:42:00Z', '2023-10-12T15:44:41Z', '2023-10-14T20:12:48Z',
'2023-10-24T20:22:05Z', '2023-10-26T11:30:18Z', '2023-10-27T12:33:30Z', '2023-10-27T14:15:05Z',
'2023-10-27T14:20:04Z', '2023-11-01T14:46:42Z', '2023-12-12T17:05:26Z', '2023-12-14T19:21:03Z']
def td():
expire_date = datetime.datetime.now() + datetime.timedelta(days=60)
sps = [t for t in test if parser.parse(t).timestamp() <= expire_date.timestamp()]
return sps
def rd():
expire_date = datetime.datetime.now() + relativedelta(days=60)
sps = [t for t in test if parser.parse(t).timestamp() <= expire_date.timestamp()]
return sps
def md():
expire_date = maya.now().add(days=60)
sps = [t for t in test if maya.when(t, timezone='US/Central') <= expire_date]
return sps
timeit.timeit('td()', 'from __main__ import td', number=100)
## 0.4771150827873498 seconds
timeit.timeit('rd()', 'from __main__ import rd', number=100)
## 0.4616425419226289 seconds
timeit.timeit('md()', 'from __main__ import md', number=100)
## 28.525230166967958 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment