Re: [Python-Dev] Why not using the hash when comparing strings?

2012-10-19 Thread Brett Cannon
On Fri, Oct 19, 2012 at 8:36 AM, Victor Stinner wrote: > 2012/10/19 Benjamin Peterson : > > It would be interesting to see how common it is for strings which have > > their hash computed to be compared. > > I implemented a quick hack. When running "./python -m test test_os": > Python calls PyUnico

Re: [Python-Dev] Why not using the hash when comparing strings?

2012-10-19 Thread Oscar Benjamin
On 19 October 2012 11:02, Duncan Booth wrote: > Hrvoje Niksic wrote: > >> On 10/19/2012 03:22 AM, Benjamin Peterson wrote: >>> It would be interesting to see how common it is for strings which have >>> their hash computed to be compared. >> >> Since all identifier-like strings mentioned in Python

Re: [Python-Dev] Why not using the hash when comparing strings?

2012-10-19 Thread Benjamin Peterson
2012/10/19 Duncan Booth : > Hrvoje Niksic wrote: > >> On 10/19/2012 03:22 AM, Benjamin Peterson wrote: >>> It would be interesting to see how common it is for strings which have >>> their hash computed to be compared. >> >> Since all identifier-like strings mentioned in Python are interned, and >>

Re: [Python-Dev] Why not using the hash when comparing strings?

2012-10-19 Thread Victor Stinner
2012/10/19 Benjamin Peterson : > It would be interesting to see how common it is for strings which have > their hash computed to be compared. I implemented a quick hack. When running "./python -m test test_os": Python calls PyUnicode_RichCompare() 15206 times with Py_EQ or Py_NE operator. In 41.4%

Re: [Python-Dev] Why not using the hash when comparing strings?

2012-10-19 Thread Duncan Booth
Hrvoje Niksic wrote: > On 10/19/2012 03:22 AM, Benjamin Peterson wrote: >> It would be interesting to see how common it is for strings which have >> their hash computed to be compared. > > Since all identifier-like strings mentioned in Python are interned, and > therefore have had their hash co

Re: [Python-Dev] Why not using the hash when comparing strings?

2012-10-19 Thread Hrvoje Niksic
On 10/19/2012 03:22 AM, Benjamin Peterson wrote: It would be interesting to see how common it is for strings which have their hash computed to be compared. Since all identifier-like strings mentioned in Python are interned, and therefore have had their hash computed, I would imagine comparing

Re: [Python-Dev] Why not using the hash when comparing strings?

2012-10-18 Thread MRAB
On 2012-10-19 02:03, Victor Stinner wrote: Hi, I would like to know if there a reason for not using the hash of (bytes or unicode) strings when comparing two objects and the hash of the two objects was already been computed. Using the hash would speed up comparaison of long strings when the two

Re: [Python-Dev] Why not using the hash when comparing strings?

2012-10-18 Thread Benjamin Peterson
2012/10/18 Victor Stinner : > Hi, > > I would like to know if there a reason for not using the hash of > (bytes or unicode) strings when comparing two objects and the hash of > the two objects was already been computed. Using the hash would speed > up comparaison of long strings when the two string

Re: [Python-Dev] Why not using the hash when comparing strings?

2012-10-18 Thread Steven D'Aprano
On 19/10/12 12:03, Victor Stinner wrote: Hi, I would like to know if there a reason for not using the hash of (bytes or unicode) strings when comparing two objects and the hash of the two objects was already been computed. Using the hash would speed up comparaison of long strings when the two st

[Python-Dev] Why not using the hash when comparing strings?

2012-10-18 Thread Victor Stinner
Hi, I would like to know if there a reason for not using the hash of (bytes or unicode) strings when comparing two objects and the hash of the two objects was already been computed. Using the hash would speed up comparaison of long strings when the two strings are different. Something like: