#441 optimize copr_log_hitcounter.py for speed a bit
Merged 5 years ago by msuchy. Opened 5 years ago by msuchy.
copr/ msuchy/copr optimize  into  master

@@ -61,6 +61,7 @@ 

  

      first_line = None

      last_line = None

+     ignore_networks = map(IPNetwork, args.ignore_subnets)

      with open(sys.argv[1], 'r') as logfile:

          logline = None

          for logline in logfile:
@@ -75,9 +76,9 @@ 

                  continue

  

              ignore = False

-             for ignore_subnet in args.ignore_subnets:

+             for ignore_subnet in ignore_networks:

                  try:

-                     if IPAddress(m.group('ip_address')) in IPNetwork(ignore_subnet):

+                     if IPAddress(m.group('ip_address')) in ignore_subnet:

                          ignore = True

                          break

                  except netaddr.core.AddrFormatError:

no initial comment

I'd really appreciate some git-log comments, e.g. how faster the code is, how did you get to it (profiler?), is the code fast enough now?

Otherwise +1

I did not profile this.
This is in a middle of loop looping over sever GB big file. So I was basically looking for any code, which can be put out from this loop.
Here the class was created during every cycle again and again despite the fact that it does not change at all.

Ok, I was curious whether it actually helps or not.. It's rather blind attempt, but +1 anyways.

Pull-Request has been merged by msuchy

5 years ago
Metadata