Skip to content

Commit

Permalink
Use KiB and MiB as units instead of kB and MB. (#199)
Browse files Browse the repository at this point in the history
* Use KiB and MiB as units instead of kB and MB.

Previously, pyperf stated the memory usage as kB and MB, while strictly
speaking, it was measured in KiB and MiB.
This commit makes it clear that the memory is measured using 2^10 and
2^20 bytes, not 10^3 and 10^6.

* Fix typo: kiB -> KiB
  • Loading branch information
yngvem authored Aug 15, 2024
1 parent c6c33d9 commit 432c419
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pyperf/_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def format_filesize(size):
return '%.0f byte' % size

if size > 10 * 1024 * 1024:
return '%.1f MB' % (size / (1024.0 * 1024.0))
return '%.1f MiB' % (size / (1024.0 * 1024.0))

return '%.1f kB' % (size / 1024.0)
return '%.1f KiB' % (size / 1024.0)


def format_filesizes(sizes):
Expand Down
6 changes: 3 additions & 3 deletions pyperf/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CpuFunctionsTests(unittest.TestCase):
stepping\t: 9
microcode\t: 0x1c
cpu MHz\t\t: 1287.554
cache size\t: 4096 KB
cache size\t: 4096 KiB
physical id\t: 0
siblings\t: 4
core id\t\t: 0
Expand All @@ -82,7 +82,7 @@ class CpuFunctionsTests(unittest.TestCase):
stepping\t: 9
microcode\t: 0x1c
cpu MHz\t\t: 1225.363
cache size\t: 4096 KB
cache size\t: 4096 KiB
physical id\t: 0
siblings\t: 4
core id\t\t: 0
Expand All @@ -109,7 +109,7 @@ class CpuFunctionsTests(unittest.TestCase):
stepping\t: 9
microcode\t: 0x1c
cpu MHz\t\t: 1200.101
cache size\t: 4096 KB
cache size\t: 4096 KiB
physical id\t: 0
siblings\t: 4
core id\t\t: 1
Expand Down
14 changes: 7 additions & 7 deletions pyperf/tests/test_perf_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,13 @@ def test_dump(self):
def test_dump_track_memory(self):
expected = """
Run 1: calibrate the number of loops: 2^15
- calibrate 1: 7188.0 kB (loops: 2^15)
- calibrate 1: 7188.0 KiB (loops: 2^15)
Run 2: 0 warmups, 1 value, 2^15 loops
- value 1: 7188.0 kB
- value 1: 7188.0 KiB
Run 3: 0 warmups, 1 value, 2^15 loops
- value 1: 7192.0 kB
- value 1: 7192.0 KiB
Run 4: 0 warmups, 1 value, 2^15 loops
- value 1: 7208.0 kB
- value 1: 7208.0 KiB
"""
filename = os.path.join(TESTDIR, 'track_memory.json')
stdout = self.run_command('dump', filename)
Expand Down Expand Up @@ -595,7 +595,7 @@ def test_dump_verbose(self):
date: 2016-10-21 03:14:19.670631
duration: 338 ms
load_avg_1min: 0.29
mem_max_rss: 13.4 MB
mem_max_rss: 13.4 MiB
runnable_threads: 1
uptime: 2 day 2 hour 4 min
Run 2: 1 warmup, 3 values, 8 loops
Expand All @@ -609,7 +609,7 @@ def test_dump_verbose(self):
date: 2016-10-21 03:14:20.496710
duration: 723 ms
load_avg_1min: 0.29
mem_max_rss: 13.5 MB
mem_max_rss: 13.5 MiB
runnable_threads: 1
uptime: 2 day 2 hour 4 min
"""
Expand Down Expand Up @@ -689,7 +689,7 @@ def _check_track_memory(self, track_option):
'[1,2]*1000',
'-o', tmp_name)
bench = pyperf.Benchmark.load(tmp_name)

self._check_track_memory_bench(bench, loops=5)

def test_track_memory(self):
Expand Down
4 changes: 2 additions & 2 deletions pyperf/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ def test_format_filesize(self):
self.assertEqual(format_filesize(1),
'1 byte')
self.assertEqual(format_filesize(10 * 1024),
'10.0 kB')
'10.0 KiB')
self.assertEqual(format_filesize(12.4 * 1024 * 1024),
'12.4 MB')
'12.4 MiB')

def test_get_python_names(self):
self.assertEqual(utils.get_python_names('/usr/bin/python3.6',
Expand Down

0 comments on commit 432c419

Please sign in to comment.