diff --git a/benchmarks/basic_commands.py b/benchmarks/basic_commands.py index d99e66b6e060e806ecb48bba9afefcaefe00c097_YmVuY2htYXJrcy9iYXNpY19jb21tYW5kcy5weQ==..9ccddb7e330b0eab5593c31d63a29440fa5f56a1_YmVuY2htYXJrcy9iYXNpY19jb21tYW5kcy5weQ== 100644 --- a/benchmarks/basic_commands.py +++ b/benchmarks/basic_commands.py @@ -138,6 +138,6 @@ class ExchangeTrackSuite(BaseTrackTestSuite): - param_names = BaseTrackTestSuite.param_names + ['single_rev', 'revset'] - params = BaseTrackTestSuite.params + [[True, False]] + [['default~10']] + param_names = BaseTrackTestSuite.param_names + ['revset'] + params = BaseTrackTestSuite.params + [['default~10', None]] @@ -143,4 +143,4 @@ - def setup(self, repo_name, single_rev, revset, *args, **kwargs): + def setup(self, repo_name, revset, *args, **kwargs): super(ExchangeTrackSuite, self).setup(repo_name, *args, **kwargs) @@ -145,6 +145,8 @@ super(ExchangeTrackSuite, self).setup(repo_name, *args, **kwargs) - self.single_rev = single_rev + self.revset = revset + + self.cachedir = os.path.join(REPOS_DIR, '.cache') from base64 import b64encode @@ -148,6 +150,4 @@ from base64 import b64encode - self.safe_range = b64encode(revset) - self.tempdir = tempfile.mkdtemp(dir=os.environ.get('ASVTEMPDIR')) @@ -153,3 +153,3 @@ - if single_rev is False: + if revset is None: self.cache_name = "%s.tar" % repo_name @@ -155,7 +155,7 @@ self.cache_name = "%s.tar" % repo_name - self.cache_path = os.path.join(self.tempdir, self.cache_name) + self.cache_path = os.path.join(self.cachedir, self.cache_name) if not os.path.isfile(self.cache_path): tar_cmd = "tar cf %s -C %s ." % (self.cache_path, self.repo_path) self._single_execute(shlex.split(tar_cmd)) else: @@ -157,10 +157,11 @@ if not os.path.isfile(self.cache_path): tar_cmd = "tar cf %s -C %s ." % (self.cache_path, self.repo_path) self._single_execute(shlex.split(tar_cmd)) else: - self.cache_name = "%s-%s-%s.tar" % (repo_name, single_rev, self.safe_range) - self.cache_path = os.path.join(self.tempdir, self.cache_name) + safe_range = b64encode(revset) + self.cache_name = "%s-%s.tar" % (repo_name, safe_range) + self.cache_path = os.path.join(self.cachedir, self.cache_name) if not os.path.isfile(self.cache_path): # First clone it @@ -164,7 +165,7 @@ if not os.path.isfile(self.cache_path): # First clone it - clone_path = os.path.join(self.tempdir, "%s-%s-clone" % (repo_name, self.safe_range)) + clone_path = os.path.join(self.cachedir, "%s-%s-clone" % (repo_name, safe_range)) rev = self._identify_id(revset) @@ -178,5 +179,11 @@ shutil.rmtree(clone_path) - def teardown(self, *args, **kwargs): + def _identify_id(self, revset): + rev = subprocess.check_output([ + self.hgpath, '--cwd', self.repo_path, 'identify', '-i', "-r", revset], env=self.environ) + return rev.strip() + + @contextlib.contextmanager + def clone_from_cache(self): try: @@ -182,7 +189,59 @@ try: - shutil.rmtree(self.tempdir) - except Exception: - pass + import time + clone_path = os.path.join(self.cachedir, 'clone-%s' % time.time()) + + os.mkdir(clone_path) + + cmd = "tar xf %s -C %s" % (self.cache_path, clone_path) + clone_time = self._single_execute(shlex.split(cmd)) + + yield clone_path + + finally: + shutil.rmtree(clone_path) + + def track_incoming(self, repo_name, revset): + with self.clone_from_cache() as clone_path: + cmd = [self.hgpath, '--cwd', clone_path, 'incoming', self.repo_path] + if revset: + cmd.extend(['-r', 'default']) + + # Ignore the return code + return self._timeit(self._single_execute, (cmd, False)) + + def track_outgoing(self, repo_name, revset): + with self.clone_from_cache() as clone_path: + cmd = [self.hgpath, '--cwd', self.repo_path, 'outgoing', + clone_path] + if revset: + cmd.extend(['-r', 'default']) + + # Ignore the return code + return self._timeit(self._single_execute, (cmd, False)) + + def track_push(self, repo_name, revset): + def clone_and_push(): + with self.clone_from_cache() as clone_path: + cmd = [self.hgpath, '--cwd', self.repo_path, 'push', '-f', + clone_path] + if revset: + cmd.extend(['-r', 'default']) + return self._single_execute(cmd, False) + return self._timeit(clone_and_push) + + +class CloneTrackSuite(BaseTrackTestSuite): + + param_names = BaseTrackTestSuite.param_names + ['single_rev', 'revset'] + params = BaseTrackTestSuite.params + [[True, False]] + [['default~10']] + + def track_clone(self, repo_name, single_rev, revset): + revset = 'default' if single_rev else None + + def clone(): + with self.clone(revset=revset) as (_, clone_time): + return clone_time + return self._timeit(clone) def _identify_id(self, revset): rev = subprocess.check_output([ @@ -202,56 +261,3 @@ yield clone_path, clone_time finally: shutil.rmtree(clone_path) - - @contextlib.contextmanager - def clone_from_cache(self): - try: - import time - clone_path = os.path.join(self.tempdir, 'clone-%s' % time.time()) - - os.mkdir(clone_path) - - cmd = "tar xf %s -C %s" % (self.cache_path, clone_path) - clone_time = self._single_execute(shlex.split(cmd)) - - yield clone_path - - finally: - shutil.rmtree(clone_path) - - def track_incoming(self, repo_name, single_rev, revset): - with self.clone_from_cache() as clone_path: - cmd = [self.hgpath, '--cwd', clone_path, 'incoming', self.repo_path] - if single_rev: - cmd.extend(['-r', 'default']) - - # Ignore the return code - return self._timeit(self._single_execute, (cmd, False)) - - def track_outgoing(self, repo_name, single_rev, revset): - with self.clone_from_cache() as clone_path: - cmd = [self.hgpath, '--cwd', self.repo_path, 'outgoing', - clone_path] - if single_rev: - cmd.extend(['-r', 'default']) - - # Ignore the return code - return self._timeit(self._single_execute, (cmd, False)) - - def track_push(self, repo_name, single_rev, revset): - def clone_and_push(): - with self.clone_from_cache() as clone_path: - cmd = [self.hgpath, '--cwd', self.repo_path, 'push', '-f', - clone_path] - if single_rev: - cmd.extend(['-r', 'default']) - return self._single_execute(cmd, False) - return self._timeit(clone_and_push) - - def track_clone(self, repo_name, single_rev, revset): - revset = 'default' if single_rev else None - - def clone(): - with self.clone(revset=revset) as (_, clone_time): - return clone_time - return self._timeit(clone)