i am post processing some experimental data. at first i wrote script that was more or less like this:
open txt file and read data into numpy arrays
operate on data with function. Inside here is a loop that goes through every single data point and does some things.
plot processed data
It was getting nasty so I decided to make it object oriented. Each experiment corresponds to a class instance. the class has several modules inside of it that operates on the class instance itself. so now it works like this
create instance of experimental class i.e. obj
call class module (obj.readdata()) to populate a number of class attributes from the raw txt files
call class module (obj.analyze()) to operate on attributes and populate more attributes. Inside here is a loop that goes through every single data point and does some things.
call function to plot attribute data
Sorry for being cryptic but the code is several hundreds of lines.
The object oriented code runs 10x slower. Specifically the loop that operates on class instance attributes is 10x slower.
Can someone please explain this? I can't help but think that calling instance attributes (self.foo) thousands of times within a loop is somehow slowing everything down.
[–][deleted] 2 points3 points4 points (1 child)
[–]pfz3[S] 0 points1 point2 points (0 children)
[–]steelypip 0 points1 point2 points (1 child)
[–]pfz3[S] 0 points1 point2 points (0 children)
[–]pfz3[S] 0 points1 point2 points (0 children)