Determine Size of Pickled Datetime
Question: I am currently pickling a python `datetime` to be passed to a task via celery,
and am running into memory issues. I'd like to find a way to determine the
resulting size of pickling a `datetime` object so that I can compare it to
pickling the unix timestamp. I realize the timestamp will be smaller, but I
specifically want to compare the sizes of both pickled objects.


Answer: A pickled object is just an array of bytes (think ASCII encoded string). So,
use `dumps` to get the bytes and look at the length. On my machine, a pickled
`datetime` is 44 bytes. This includes some overhead, e.g., it will include a
head indicating the pickle protocol version.

    
    
    import datetime
    import pickle
    
    dt = datetime.datetime.now()
    size = len(pickle.dumps(dt))
    print(size, 'bytes')
    

Also, if you use a higher protocol, the resulting pickled object should be
smaller. Try `protocol=pickle.HIGHEST_PROTOCOL` in the `dump`.

