prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  ProgressBar iters/sec is too low in CPU mode
  The 'iters/sec' speed displayed in the `ProgressBar` extension seems too low when running a model in CPU mode. I suspect this is due to the use of `time.clock()` instead of `time.time()`. `time.clock()` apparently measures the total time spent in all CPU cores, which can cause the measured time to (sometimes greatly) exceed the wall clock time.
  
  
  </issue>
  <code>
  [start of chainer/training/extensions/progress_bar.py]
  1 from __future__ import division
  2 import datetime
  3 import sys
  4 import time
  5 
  6 from chainer.training import extension
  7 from chainer.training import trigger
  8 
  9 
  10 class ProgressBar(extension.Extension):
  11 
  12     """Trainer extension to print a progress bar and recent training status.
  13 
  14     This extension prints a progress bar at every call. It watches the current
  15     iteration and epoch to print the bar.
  16 
  17     Args:
  18         training_length (tuple): Length of whole training. It consists of an
  19             integer and either ``'epoch'`` or ``'iteration'``. If this value is
  20             omitted and the stop trigger of the trainer is
  21             :class:`IntervalTrigger`, this extension uses its attributes to
  22             determine the length of the training.
  23         update_interval (int): Number of iterations to skip printing the
  24             progress bar.
  25         bar_length (int): Length of the progress bar in characters.
  26         out: Stream to print the bar. Standard output is used by default.
  27 
  28     """
  29     def __init__(self, training_length=None, update_interval=100,
  30                  bar_length=50, out=sys.stdout):
  31         self._training_length = training_length
  32         self._status_template = None
  33         self._update_interval = update_interval
  34         self._bar_length = bar_length
  35         self._out = out
  36         self._recent_timing = []
  37 
  38     def __call__(self, trainer):
  39         training_length = self._training_length
  40 
  41         # initialize some attributes at the first call
  42         if training_length is None:
  43             t = trainer.stop_trigger
  44             if not isinstance(t, trigger.IntervalTrigger):
  45                 raise TypeError(
  46                     'cannot retrieve the training length from %s' % type(t))
  47             training_length = self._training_length = t.period, t.unit
  48 
  49         stat_template = self._status_template
  50         if stat_template is None:
  51             stat_template = self._status_template = (
  52                 '{0.iteration:10} iter, {0.epoch} epoch / %s %ss\n' %
  53                 training_length)
  54 
  55         length, unit = training_length
  56         out = self._out
  57 
  58         iteration = trainer.updater.iteration
  59 
  60         # print the progress bar
  61         if iteration % self._update_interval == 0:
  62             epoch = trainer.updater.epoch_detail
  63             recent_timing = self._recent_timing
  64             now = time.clock()
  65 
  66             if len(recent_timing) >= 1:
  67                 out.write('\033[J')
  68 
  69                 if unit == 'iteration':
  70                     rate = iteration / length
  71                 else:
  72                     rate = epoch / length
  73 
  74                 bar_length = self._bar_length
  75                 marks = '#' * int(rate * bar_length)
  76                 out.write('     total [{}{}] {:6.2%}\n'.format(
  77                     marks, '.' * (bar_length - len(marks)), rate))
  78 
  79                 epoch_rate = epoch - int(epoch)
  80                 marks = '#' * int(epoch_rate * bar_length)
  81                 out.write('this epoch [{}{}] {:6.2%}\n'.format(
  82                     marks, '.' * (bar_length - len(marks)), epoch_rate))
  83 
  84                 status = stat_template.format(trainer.updater)
  85                 out.write(status)
  86 
  87                 old_t, old_e, old_sec = recent_timing[0]
  88                 speed_t = (iteration - old_t) / (now - old_sec)
  89                 speed_e = (epoch - old_e) / (now - old_sec)
  90                 if unit == 'iteration':
  91                     estimated_time = (length - iteration) / speed_t
  92                 else:
  93                     estimated_time = (length - epoch) / speed_e
  94                 out.write('{:10.5g} iters/sec. Estimated time to finish: {}.\n'
  95                           .format(speed_t,
  96                                   datetime.timedelta(seconds=estimated_time)))
  97 
  98                 # move the cursor to the head of the progress bar
  99                 out.write('\033[4A')
  100                 out.flush()
  101 
  102                 if len(recent_timing) > 100:
  103                     del recent_timing[0]
  104 
  105             recent_timing.append((iteration, epoch, now))
  106 
  107     def finalize(self):
  108         # delete the progress bar
  109         out = self._out
  110         out.write('\033[J')
  111         out.flush()
  112
  [end of chainer/training/extensions/progress_bar.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/chainer/training/extensions/progress_bar.py b/chainer/training/extensions/progress_bar.py
  --- a/chainer/training/extensions/progress_bar.py
  +++ b/chainer/training/extensions/progress_bar.py
  @@ -61,7 +61,7 @@
           if iteration % self._update_interval == 0:
               epoch = trainer.updater.epoch_detail
               recent_timing = self._recent_timing
  -            now = time.clock()
  +            now = time.time()
   
               if len(recent_timing) >= 1:
                   out.write('\033[J')
  
verification_info: {"golden_diff": "diff --git a/chainer/training/extensions/progress_bar.py b/chainer/training/extensions/progress_bar.py\n--- a/chainer/training/extensions/progress_bar.py\n+++ b/chainer/training/extensions/progress_bar.py\n@@ -61,7 +61,7 @@\n         if iteration % self._update_interval == 0:\n             epoch = trainer.updater.epoch_detail\n             recent_timing = self._recent_timing\n-            now = time.clock()\n+            now = time.time()\n \n             if len(recent_timing) >= 1:\n                 out.write('\\033[J')\n", "issue": "ProgressBar iters/sec is too low in CPU mode\nThe 'iters/sec' speed displayed in the `ProgressBar` extension seems too low when running a model in CPU mode. I suspect this is due to the use of `time.clock()` instead of `time.time()`. `time.clock()` apparently measures the total time spent in all CPU cores, which can cause the measured time to (sometimes greatly) exceed the wall clock time.\n\n", "before_files": [{"content": "from __future__ import division\nimport datetime\nimport sys\nimport time\n\nfrom chainer.training import extension\nfrom chainer.training import trigger\n\n\nclass ProgressBar(extension.Extension):\n\n    \"\"\"Trainer extension to print a progress bar and recent training status.\n\n    This extension prints a progress bar at every call. It watches the current\n    iteration and epoch to print the bar.\n\n    Args:\n        training_length (tuple): Length of whole training. It consists of an\n            integer and either ``'epoch'`` or ``'iteration'``. If this value is\n            omitted and the stop trigger of the trainer is\n            :class:`IntervalTrigger`, this extension uses its attributes to\n            determine the length of the training.\n        update_interval (int): Number of iterations to skip printing the\n            progress bar.\n        bar_length (int): Length of the progress bar in characters.\n        out: Stream to print the bar. Standard output is used by default.\n\n    \"\"\"\n    def __init__(self, training_length=None, update_interval=100,\n                 bar_length=50, out=sys.stdout):\n        self._training_length = training_length\n        self._status_template = None\n        self._update_interval = update_interval\n        self._bar_length = bar_length\n        self._out = out\n        self._recent_timing = []\n\n    def __call__(self, trainer):\n        training_length = self._training_length\n\n        # initialize some attributes at the first call\n        if training_length is None:\n            t = trainer.stop_trigger\n            if not isinstance(t, trigger.IntervalTrigger):\n                raise TypeError(\n                    'cannot retrieve the training length from %s' % type(t))\n            training_length = self._training_length = t.period, t.unit\n\n        stat_template = self._status_template\n        if stat_template is None:\n            stat_template = self._status_template = (\n                '{0.iteration:10} iter, {0.epoch} epoch / %s %ss\\n' %\n                training_length)\n\n        length, unit = training_length\n        out = self._out\n\n        iteration = trainer.updater.iteration\n\n        # print the progress bar\n        if iteration % self._update_interval == 0:\n            epoch = trainer.updater.epoch_detail\n            recent_timing = self._recent_timing\n            now = time.clock()\n\n            if len(recent_timing) >= 1:\n                out.write('\\033[J')\n\n                if unit == 'iteration':\n                    rate = iteration / length\n                else:\n                    rate = epoch / length\n\n                bar_length = self._bar_length\n                marks = '#' * int(rate * bar_length)\n                out.write('     total [{}{}] {:6.2%}\\n'.format(\n                    marks, '.' * (bar_length - len(marks)), rate))\n\n                epoch_rate = epoch - int(epoch)\n                marks = '#' * int(epoch_rate * bar_length)\n                out.write('this epoch [{}{}] {:6.2%}\\n'.format(\n                    marks, '.' * (bar_length - len(marks)), epoch_rate))\n\n                status = stat_template.format(trainer.updater)\n                out.write(status)\n\n                old_t, old_e, old_sec = recent_timing[0]\n                speed_t = (iteration - old_t) / (now - old_sec)\n                speed_e = (epoch - old_e) / (now - old_sec)\n                if unit == 'iteration':\n                    estimated_time = (length - iteration) / speed_t\n                else:\n                    estimated_time = (length - epoch) / speed_e\n                out.write('{:10.5g} iters/sec. Estimated time to finish: {}.\\n'\n                          .format(speed_t,\n                                  datetime.timedelta(seconds=estimated_time)))\n\n                # move the cursor to the head of the progress bar\n                out.write('\\033[4A')\n                out.flush()\n\n                if len(recent_timing) > 100:\n                    del recent_timing[0]\n\n            recent_timing.append((iteration, epoch, now))\n\n    def finalize(self):\n        # delete the progress bar\n        out = self._out\n        out.write('\\033[J')\n        out.flush()\n", "path": "chainer/training/extensions/progress_bar.py"}]}