This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: show median in benchmark results
Type: enhancement Stage: patch review
Components: Benchmarks Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: pitrou, scoder, serhiy.storchaka, vstinner, wolma
Priority: normal Keywords: patch

Created on 2014-11-16 09:50 by scoder, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
show_median.patch scoder, 2014-11-16 09:50 show median in addition to min and avg timings
show_median.patch scoder, 2014-11-16 10:28 update: use average of middle values for even sample size
show_median.patch scoder, 2015-05-03 11:06 update: fix median calculation for even number of samples
Messages (16)
msg231239 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2014-11-16 09:50
The median tends to give a better idea about benchmark results than an average as it inherently ignores outliers.
msg231241 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-11-16 10:14
In case of even number of samples the median value is calculated as arithmetic mean of two middle samples.

med_base = (base_times[len(base_times)//2] + base_times[(len(base_times)-1)//2]) / 2
msg231243 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2014-11-16 10:28
Fair enough, patch updated.
msg242050 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2015-04-26 07:55
Any more comments on the patch, or can it be applied?
msg242078 - (view) Author: Wolfgang Maier (wolma) * Date: 2015-04-26 20:32
for the even number case, I think you shouldn't do // 2, but / 2.

In general, wouldn't it be good to let the statistics module do all the stats calculations?
msg242079 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2015-04-26 20:35
> In general, wouldn't it be good to let the statistics module do all the stats calculations?

It's not available in older Python versions, e.g. 2.6.
msg242080 - (view) Author: Wolfgang Maier (wolma) * Date: 2015-04-26 20:38
> It's not available in older Python versions, e.g. 2.6.

I know, I was talking about 3.5+, of course. This would not be backported to Python2 anyway, would it?
msg242081 - (view) Author: Wolfgang Maier (wolma) * Date: 2015-04-26 20:51
ah sorry, it's late here already and I forgot what file this change is about. So forget my last comment then.
msg242461 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2015-05-03 11:06
> for the even number case, I think you shouldn't do // 2, but / 2.

Right. I updated the patch.
msg242463 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2015-05-03 11:14
Have you found the median to be more stable than the minimum here?
msg242464 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2015-05-03 11:41
I'm actually not sure how it relates to the minimum. The more runs you have, the higher the chance of hitting the actual minimum at least once. And if none of the runs hits the real minimum, you're simply out of luck.

However, it should tend to give a much better result than the (currently printed) average, which suffers from outliers. And outliers are almost always too high for benchmarks and never too low, due to various external influences.
msg242465 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2015-05-03 11:45
Then let's just replace the average with the median? I don't think it makes sense to add more statistical information to the output (IMHO, there is already too much of it :-)).
msg242466 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-05-03 11:52
May be just drop 5% of largest values to avoid the impact of outliers?

See also issue23552.
msg242467 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2015-05-03 11:58
Well, we can apply a kludge, or apply statistics.
msg242469 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2015-05-03 12:25
> May be just drop 5% of largest values to avoid the impact of outliers?

In fast mode (option "-f"), there may not be enough samples for that.
msg273926 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-08-30 16:22
The new https://github.com/python/performance benchmark suite now displays the median rather than the arithmetic mean (average) by default (it also displays the standard deviation).

See the perf issue for a discussion about median vs mean:
https://github.com/haypo/perf/issues/1

Can we now close this issue?
History
Date User Action Args
2022-04-11 14:58:10adminsetgithub: 67070
2016-09-01 19:27:35scodersetstatus: open -> closed
resolution: fixed
2016-08-30 16:22:27vstinnersetnosy: + vstinner
messages: + msg273926
2015-05-03 12:25:33pitrousetmessages: + msg242469
2015-05-03 11:58:09scodersetmessages: + msg242467
2015-05-03 11:52:11serhiy.storchakasetmessages: + msg242466
2015-05-03 11:45:44pitrousetmessages: + msg242465
2015-05-03 11:41:46scodersetmessages: + msg242464
2015-05-03 11:14:33pitrousetmessages: + msg242463
2015-05-03 11:06:31scodersetfiles: + show_median.patch

messages: + msg242461
2015-04-26 20:51:28wolmasetmessages: + msg242081
2015-04-26 20:38:02wolmasetmessages: + msg242080
2015-04-26 20:35:15scodersetmessages: + msg242079
2015-04-26 20:32:38wolmasetmessages: + msg242078
2015-04-26 20:20:21wolmasetnosy: + wolma
2015-04-26 07:55:43scodersetmessages: + msg242050
2014-11-16 10:28:15scodersetfiles: + show_median.patch

messages: + msg231243
2014-11-16 10:14:45serhiy.storchakasetmessages: + msg231241
2014-11-16 10:14:21serhiy.storchakasetmessages: - msg231240
2014-11-16 10:06:58serhiy.storchakasetnosy: + serhiy.storchaka

messages: + msg231240
stage: patch review
2014-11-16 09:50:17scodercreate