What are the different use cases of joblib versus pickle?

前端 未结 3 1889
独厮守ぢ
独厮守ぢ 2020-12-02 07:40

Background: I\'m just getting started with scikit-learn, and read at the bottom of the page about joblib, versus pickle.

it may be more interesting t

3条回答
  •  时光取名叫无心
    2020-12-02 08:04

    Thanks to Gunjan for giving us this script! I modified it for Python3 results

    #comapare pickle loaders
    from time import time
    import pickle
    import os
    import _pickle as cPickle
    from sklearn.externals import joblib
    
    file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'database.clf')
    t1 = time()
    lis = []
    d = pickle.load(open(file,"rb"))
    print("time for loading file size with pickle", os.path.getsize(file),"KB =>", time()-t1)
    
    t1 = time()
    cPickle.load(open(file,"rb"))
    print("time for loading file size with cpickle", os.path.getsize(file),"KB =>", time()-t1)
    
    t1 = time()
    joblib.load(file)
    print("time for loading file size joblib", os.path.getsize(file),"KB =>", time()-t1)
    
    time for loading file size with pickle 79708 KB => 0.16768312454223633
    time for loading file size with cpickle 79708 KB => 0.0002372264862060547
    time for loading file size joblib 79708 KB => 0.0006849765777587891
    

提交回复
热议问题