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 6729511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:17:56+00:00 2026-05-26T10:17:56+00:00

In python is the process of opening a file handler slow compared to the

  • 0

In python is the process of opening a file handler slow compared to the actual write time?

One large file, one file handler

import marshal
bigDataStructure = [[1000000.0 for j in range(1000000)] for i in range(1000000)]
f = open('bigFile' , 'w')
marshal.dump(bigDataStructure , f)
f.close()

multiple smaller files, multiple file handlers

for i , row in enumerate(bigDataStructure):
 f = open(str(i) , 'w'):
 marshal.dump(row , f)
 f.close()
  • 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. Editorial Team
    Editorial Team
    2026-05-26T10:17:57+00:00Added an answer on May 26, 2026 at 10:17 am

    You mention running out of memory if you merge them all — that’s a lot of neurons. (At least, in my experience, several hundred neurons were sufficient for the toy programs we wrote in my CS courses.)

    You probably don’t want to be creating 100,000 separate files to store 100,000 separate neurons — and certainly not 1,000,000 files to store 1,000,000 neurons. The IO overhead of directory lookups, file open, read, close, and small amounts of IO will drastically weigh on loading and saving with non-trivial amounts of neurons.

    Of course, if you’re thinking 50 or 100 neurons, then it’ll go quickly no matter what, and perhaps the simplest implementation is called for.

    But if this were mine, I’d look hard at trying to build good data-structures for the neurons: perhaps all your neurons in a given level can be described by an integer to select neuron type and an array of integers or doubles to describe per-neuron characteristics, and a list of these level descriptions could be easily written to separate files or a single file, whichever is easier.

    If your neurons change types within a level, or aren’t fully connected between levels, you might find some sparse matrix storage designs useful for a larger data structure that can describe all the neurons at once.

    Maybe the real question should be “how do I improve the storage of my neurons?”

    Update

    I think even 10,000 neurons justifies making a “combined” storage format. I just created 10,000 tiny files, dropped my caches to test a cold-start, and then re-read each one individually. It took 14.6 seconds to read in 10,000 files. It took only .1 seconds to read in a single file containing the same data as the 10,000 files.

    If your network starts “cold” once a year or so, maybe it won’t matter much. But if your network starts cold a dozen times per day, you might grow to resent the simpler storage format.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to retrieve the process start time (or uptime) in python in Linux? I
In Python for *nix, does time.sleep() block the thread or the process?
I have a Python process on one Linux machine server1 that receives and processes
When using os.system to open a file, eg: os.system(r'C:/foo.txt') , the current Python process,
I would like to run a process from Python (2.4/2.5/2.6) using Popen , and
Can anyone share an efficient code snipper to daemonize a process in python?
I process a lot of text/data that I exchange between Python, R, and sometimes
I have a process id in Python. I know I can kill it with
Im in the process of writing a python script to act as a glue
I'm trying to process a delicious rss feed via python. Here's a sample: ...

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.