attachment:performance_test.py of Foundations/Webservice

Not logged in - Log In / Register

Attachment 'performance_test.py'

Download

   1 import os
   2 import shutil
   3 import time
   4 import tempfile
   5 
   6 import_before = time.time()
   7 from launchpadlib.launchpad import Launchpad
   8 import_after = time.time()
   9 print "Import cost: %.2f sec" % (import_after-import_before)
  10 
  11 #import httplib2
  12 #httplib2.debuglevel = 1
  13 
  14 num_trials = 30
  15 def make_request():
  16     bugs = [x for x in launchpad.bugs[:5]]
  17 
  18 cache_dir = tempfile.mkdtemp()
  19 startup_before = time.time()
  20 launchpad = Launchpad.login(
  21     'launchpad-library', 'salgado-change-anything', 'test',
  22     service_root='https://api.launchpad.dev/', version="devel",
  23     cache=cache_dir)
  24 startup_after = time.time()
  25 
  26 print "Startup cost: %.2f sec" % (startup_after-startup_before)
  27 
  28 samples = []
  29 for i in range(0,num_trials):
  30     before = time.time()
  31     make_request()
  32     after = time.time()
  33     samples.append(after-before)
  34 
  35 print "First fetch took %.2f sec" % samples[0]
  36 
  37 first_five_total = sum(samples[:5])
  38 first_five_mean = first_five_total/5
  39 print "First five fetches took %.2f sec (mean: %.2f sec)" % (
  40     first_five_total, first_five_mean)
  41 
  42 total = sum(samples)
  43 mean = total / len(samples)
  44 print "All %d fetches took %.2f sec (mean: %.2f sec)" % (
  45     len(samples), total, mean)
  46 
  47 shutil.rmtree(cache_dir)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2010-03-25 18:42:37, 1.2 KB) [[attachment:performance_test.py]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.