<s> from __future__ import print_function <EOL> from io import BytesIO <EOL> from time import time <EOL> import sys <EOL> from . lib import TestBigRepoRW <EOL> from git import Commit <EOL> from gitdb import IStream <EOL> from git . compat import xrange <EOL> from git . test . test_commit import assert_commit_serialization <EOL> class TestPerformance ( TestBigRepoRW ) : <EOL> ref_100 = '<STR_LIT>' <EOL> def _query_commit_info ( self , c ) : <EOL> c . author <EOL> c . authored_date <EOL> c . author_tz_offset <EOL> c . committer <EOL> c . committed_date <EOL> c . committer_tz_offset <EOL> c . message <EOL> c . parents <EOL> def test_iteration ( self ) : <EOL> no = <NUM_LIT:0> <EOL> nc = <NUM_LIT:0> <EOL> st = time ( ) <EOL> for c in self . rorepo . iter_commits ( self . ref_100 ) : <EOL> nc += <NUM_LIT:1> <EOL> self . _query_commit_info ( c ) <EOL> for obj in c . tree . traverse ( ) : <EOL> obj . size <EOL> no += <NUM_LIT:1> <EOL> elapsed_time = time ( ) - st <EOL> print ( "<STR_LIT>" <EOL> % ( nc , no , elapsed_time , no / elapsed_time ) , file = sys . stderr ) <EOL> def test_commit_traversal ( self ) : <EOL> nc = <NUM_LIT:0> <EOL> st = time ( ) <EOL> for c in self . gitrorepo . commit ( ) . traverse ( branch_first = False ) : <EOL> nc += <NUM_LIT:1> <EOL> self . _query_commit_info ( c ) <EOL> elapsed_time = time ( ) - st <EOL> print ( "<STR_LIT>" <EOL> % ( nc , elapsed_time , nc / elapsed_time ) , file = sys . stderr ) <EOL> def test_commit_iteration ( self ) : <EOL> nc = <NUM_LIT:0> <EOL> st = time ( ) <EOL> for c in Commit . iter_items ( self . gitrorepo , self . gitrorepo . head ) : <EOL> nc += <NUM_LIT:1> <EOL> self . _query_commit_info ( c ) <EOL> elapsed_time = time ( ) - st <EOL> print ( "<STR_LIT>" <EOL> % ( nc , elapsed_time , nc / elapsed_time ) , file = sys . stderr ) <EOL> def test_commit_serialization ( self ) : <EOL> assert_commit_serialization ( self . gitrwrepo , '<STR_LIT>' , True ) <EOL> rwrepo = self . gitrwrepo <EOL> make_object = rwrepo . odb . store <EOL> hc = rwrepo . commit ( rwrepo . head ) <EOL> nc = <NUM_LIT> <EOL> st = time ( ) <EOL> for i in xrange ( nc ) : <EOL> cm = Commit ( rwrepo , Commit . NULL_BIN_SHA , hc . tree , <EOL> hc . author , hc . authored_date , hc . author_tz_offset , <EOL> hc . committer , hc . committed_date , hc . committer_tz_offset , <EOL> str ( i ) , parents = hc . parents , encoding = hc . encoding ) <EOL> stream = BytesIO ( ) <EOL> cm . _serialize ( stream ) <EOL> slen = stream . tell ( ) <EOL> stream . seek ( <NUM_LIT:0> ) <EOL> cm . binsha = make_object ( IStream ( Commit . type , slen , stream ) ) . binsha <EOL> elapsed = time ( ) - st <EOL> print ( "<STR_LIT>" <EOL> % ( nc , elapsed , nc / elapsed ) , file = sys . stderr ) </s>
