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-19 Thread Duncan Booth
Hrvoje Niksic hrvoje.nik...@avl.com 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

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

2012-10-19 Thread Victor Stinner
2012/10/19 Benjamin Peterson benja...@python.org: 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

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

2012-10-19 Thread Benjamin Peterson
2012/10/19 Duncan Booth duncan.bo...@suttoncourtenay.org.uk: Hrvoje Niksic hrvoje.nik...@avl.com 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

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 duncan.bo...@suttoncourtenay.org.uk wrote: Hrvoje Niksic hrvoje.nik...@avl.com 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

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 victor.stin...@gmail.comwrote: 2012/10/19 Benjamin Peterson benja...@python.org: 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

[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:

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

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

2012-10-18 Thread Benjamin Peterson
2012/10/18 Victor Stinner victor.stin...@gmail.com: 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

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