Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 126467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:19:21+00:00 2026-05-11T05:19:21+00:00

I need to load (de-serialize) a pre-computed list of integers from a file in

  • 0

I need to load (de-serialize) a pre-computed list of integers from a file in a Python script (into a Python list). The list is large (upto millions of items), and I can choose the format I store it in, as long as loading is fastest.

Which is the fastest method, and why?

  1. Using import on a .py file that just contains the list assigned to a variable
  2. Using cPickle‘s load
  3. Some other method (perhaps numpy?)

Also, how can one benchmark such things reliably?

Addendum: measuring this reliably is difficult, because import is cached so it can’t be executed multiple times in a test. The loading with pickle also gets faster after the first time probably because page-precaching by the OS. Loading 1 million numbers with cPickle takes 1.1 sec the first time run, and 0.2 sec on subsequent executions of the script.

Intuitively I feel cPickle should be faster, but I’d appreciate numbers (this is quite a challenge to measure, I think).

And yes, it’s important for me that this performs quickly.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:19:21+00:00Added an answer on May 11, 2026 at 5:19 am

    I would guess cPickle will be fastest if you really need the thing in a list.

    If you can use an array, which is a built-in sequence type, I timed this at a quarter of a second for 1 million integers:

    from array import array from datetime import datetime  def WriteInts(theArray,filename):     f = file(filename,'wb')     theArray.tofile(f)     f.close()  def ReadInts(filename):     d = datetime.utcnow()     theArray = array('i')     f = file(filename,'rb')     try:         theArray.fromfile(f,1000000000)     except EOFError:         pass     print 'Read %d ints in %s' % (len(theArray),datetime.utcnow() - d)     return theArray  if __name__ == '__main__':     a = array('i')     a.extend(range(0,1000000))     filename = 'a_million_ints.dat'     WriteInts(a,filename)     r = ReadInts(filename)     print 'The 5th element is %d' % (r[4]) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to load a .xml file from a URL adress into an NSData
I need to load a file from an umounted TrueCrypt disk into memory. Is
I need to load a custom function from an extern file but without causing
I need to serialize all inputs from a form into a JSON string. With
I need help with jQuery and ajax. need to load textarea content from file
I need to Load RVM into a shell session as a function , so
I need to load data into my treestore. My ajax request give me XML
I need to load a lot of data fetched from a mysql db in
I need to load an image from a web in a simple Java stand
I need to load a model, existing of +/- 20 tables from the database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.