Subscribe to Adventures in Spaghetti code        RSS Feed

Calculating how much global variables slow a python program down

Icon Leave Comment
I knew I had a set of about 6 variables that I needed to make global. I have a code of 6519 logical lines of code, divided into 211 functions, that's 30.9 LLOC per function. I'm refactoring right now and trying to get that number down to around 20 or 25. In any case, I would say in about 75% of those functions, I would use one of the 6 variables that I knew I needed to make into a global. I was a little afraid to do this since I feared it would slow my program down, but I also knew that the programming time of passing those 6 variables around time and again was really slowing me down. So I decided to bite the bullet and make those 6 variables global. Formally, it took 2.562 seconds to put my program through a battery of tests, that is, the best time of 3 trials. After I installed the global variables it now takes 2.831 seconds, so I only lost 15% of computing time which I think is certainly worth it.

0 Comments On This Entry


Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

December 2021

567 8 91011


    Recent Entries

    Recent Comments

    Search My Blog

    5 user(s) viewing

    5 Guests
    0 member(s)
    0 anonymous member(s)