Skip to content

Commit 432c419

Browse files
authored
Use KiB and MiB as units instead of kB and MB. (#199)
* 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
1 parent c6c33d9 commit 432c419

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

pyperf/_formatter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def format_filesize(size):
3030
return '%.0f byte' % size
3131

3232
if size > 10 * 1024 * 1024:
33-
return '%.1f MB' % (size / (1024.0 * 1024.0))
33+
return '%.1f MiB' % (size / (1024.0 * 1024.0))
3434

35-
return '%.1f kB' % (size / 1024.0)
35+
return '%.1f KiB' % (size / 1024.0)
3636

3737

3838
def format_filesizes(sizes):

pyperf/tests/test_metadata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class CpuFunctionsTests(unittest.TestCase):
5555
stepping\t: 9
5656
microcode\t: 0x1c
5757
cpu MHz\t\t: 1287.554
58-
cache size\t: 4096 KB
58+
cache size\t: 4096 KiB
5959
physical id\t: 0
6060
siblings\t: 4
6161
core id\t\t: 0
@@ -82,7 +82,7 @@ class CpuFunctionsTests(unittest.TestCase):
8282
stepping\t: 9
8383
microcode\t: 0x1c
8484
cpu MHz\t\t: 1225.363
85-
cache size\t: 4096 KB
85+
cache size\t: 4096 KiB
8686
physical id\t: 0
8787
siblings\t: 4
8888
core id\t\t: 0
@@ -109,7 +109,7 @@ class CpuFunctionsTests(unittest.TestCase):
109109
stepping\t: 9
110110
microcode\t: 0x1c
111111
cpu MHz\t\t: 1200.101
112-
cache size\t: 4096 KB
112+
cache size\t: 4096 KiB
113113
physical id\t: 0
114114
siblings\t: 4
115115
core id\t\t: 1

pyperf/tests/test_perf_cli.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -556,13 +556,13 @@ def test_dump(self):
556556
def test_dump_track_memory(self):
557557
expected = """
558558
Run 1: calibrate the number of loops: 2^15
559-
- calibrate 1: 7188.0 kB (loops: 2^15)
559+
- calibrate 1: 7188.0 KiB (loops: 2^15)
560560
Run 2: 0 warmups, 1 value, 2^15 loops
561-
- value 1: 7188.0 kB
561+
- value 1: 7188.0 KiB
562562
Run 3: 0 warmups, 1 value, 2^15 loops
563-
- value 1: 7192.0 kB
563+
- value 1: 7192.0 KiB
564564
Run 4: 0 warmups, 1 value, 2^15 loops
565-
- value 1: 7208.0 kB
565+
- value 1: 7208.0 KiB
566566
"""
567567
filename = os.path.join(TESTDIR, 'track_memory.json')
568568
stdout = self.run_command('dump', filename)
@@ -595,7 +595,7 @@ def test_dump_verbose(self):
595595
date: 2016-10-21 03:14:19.670631
596596
duration: 338 ms
597597
load_avg_1min: 0.29
598-
mem_max_rss: 13.4 MB
598+
mem_max_rss: 13.4 MiB
599599
runnable_threads: 1
600600
uptime: 2 day 2 hour 4 min
601601
Run 2: 1 warmup, 3 values, 8 loops
@@ -609,7 +609,7 @@ def test_dump_verbose(self):
609609
date: 2016-10-21 03:14:20.496710
610610
duration: 723 ms
611611
load_avg_1min: 0.29
612-
mem_max_rss: 13.5 MB
612+
mem_max_rss: 13.5 MiB
613613
runnable_threads: 1
614614
uptime: 2 day 2 hour 4 min
615615
"""
@@ -689,7 +689,7 @@ def _check_track_memory(self, track_option):
689689
'[1,2]*1000',
690690
'-o', tmp_name)
691691
bench = pyperf.Benchmark.load(tmp_name)
692-
692+
693693
self._check_track_memory_bench(bench, loops=5)
694694

695695
def test_track_memory(self):

pyperf/tests/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ def test_format_filesize(self):
146146
self.assertEqual(format_filesize(1),
147147
'1 byte')
148148
self.assertEqual(format_filesize(10 * 1024),
149-
'10.0 kB')
149+
'10.0 KiB')
150150
self.assertEqual(format_filesize(12.4 * 1024 * 1024),
151-
'12.4 MB')
151+
'12.4 MiB')
152152

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

0 commit comments

Comments
 (0)