[Tutor] Please sponsor me to run the Virgin London Marathon

2010-04-16 Thread Alexander Telford
Hi, Next Sunday I am going to run the London Marathon to raise money for Treehouse: an educational charity for children with autism that is very close to my heart. Autism is a condition which my cousin James and hundreds of thousands of other people in the UK suffer from. It impairs their abili

Re: [Tutor] Loop comparison

2010-04-16 Thread Ark
Hi. Thanks for everyone answers.  It's true, hehe, it's not a  benchmark or anything like that.  I hadn't taken into account compiler optimizations, but I have learnt a lot in this thread. About the Java code, Bigints are used. ark ___ Tutor maillist -

Re: [Tutor] Loop comparison

2010-04-16 Thread Alan Gauld
"Lie Ryan" wrote A friend of mine suggested me to do the next experiment in python and Java. It's a simple program to sum all the numbers from 0 to 10. result = i = 0 while i < 10: result += i i += 1 print result Are you sure you're not causing Java to overflow here?

Re: [Tutor] Loop comparison

2010-04-16 Thread Alan Gauld
> result = sum(range(10)) > > although it still took 10 minutes on my PC. Did you mean to say "minutes" or rather "seconds" here? And did you really mean to use "range" or rather "xrange" (or "range" in Py3)? Yes, minutes and in Python 3. And on a 2.8GHz 2 core CPU with 2G RAM su

Re: [Tutor] Loop comparison

2010-04-16 Thread Alan Gauld
"Steven D'Aprano" wrote (We can of course do some fancy math to speed this particular sum up since the result for any power of ten has a common pattern, but I wouldn't expect the compiler optimiser to be that clever) No fancy maths needed, The sum of 1,2,3,4,...,N is given by a simple for

Re: [Tutor] Loop comparison

2010-04-16 Thread Dave Angel
ALAN GAULD wrote: The precalculation optimisations are taking place. If you pass it an argument to use for the upper limit of the sequence the calculation time shoots up. I'm still confused about when the addition takes place. Surely the compiler has to do the addition, so it should

Re: [Tutor] Loop comparison

2010-04-16 Thread Lie Ryan
On 04/16/10 16:50, Ark wrote: > Hi everyone. > A friend of mine suggested me to do the next experiment in python and Java. > > It's a simple program to sum all the numbers from 0 to 10. > > result = i = 0 > while i < 10: > result += i > i += 1 > print result > Are you su

Re: [Tutor] Loop comparison

2010-04-16 Thread Stefan Behnel
Steven D'Aprano, 16.04.2010 12:00: On Fri, 16 Apr 2010 06:29:40 pm Alan Gauld wrote: "Stefan Behnel" wrote import cython @cython.locals(result=cython.longlong, i=cython.longlong) def add(): result = 0 for i in xrange(10): result += i

Re: [Tutor] Loop comparison

2010-04-16 Thread Steven D'Aprano
On Fri, 16 Apr 2010 06:25:54 pm Stefan Behnel wrote: > Alan Gauld, 16.04.2010 10:09: > > Even the built in sum() will be faster than a while loop: > > > > result = sum(range(10)) > > > > although it still took 10 minutes on my PC. > > Did you mean to say "minutes" or rather "seconds" here?

Re: [Tutor] Loop comparison

2010-04-16 Thread Steven D'Aprano
On Fri, 16 Apr 2010 06:29:40 pm Alan Gauld wrote: > "Stefan Behnel" wrote > > > import cython > > > > @cython.locals(result=cython.longlong, i=cython.longlong) > > def add(): > > result = 0 > > for i in xrange(10): > > result += i > > return

[Tutor] Python Examples of processing MS Outlook

2010-04-16 Thread Peter Meagher
Greetings, I'm doing a lot of email processing at the moment. I put together some basic code from within Outlook to open my default inbox, filter email records based on text in the Subject field, then parse the body, finally send the output to a text file. This is simple stuff but very useful

Re: [Tutor] Loop comparison

2010-04-16 Thread ALAN GAULD
> The precalculation optimisations are > taking place. If you pass it an argument to use for the upper limit of the > sequence the calculation time shoots up. I'm still confused about when the addition takes place. Surely the compiler has to do the addition, so it should be slower? I assume

Re: [Tutor] Passing headers with httplib

2010-04-16 Thread Ray Parrish
Ray Parrish wrote: Hello, I am trying to figure out how to send cookie data with an httplib request command. Here is what the doc says - request( method, url[, body[, headers]]) This will send a request to the server using the HTTP request method method and the selector url. If the b

Re: [Tutor] Loop comparison

2010-04-16 Thread Stefan Behnel
Alan Gauld, 16.04.2010 10:29: "Stefan Behnel" wrote import cython @cython.locals(result=cython.longlong, i=cython.longlong) def add(): result = 0 for i in xrange(10): result += i return result print add() This runs in less than half a second on my machine, includin

Re: [Tutor] QUESTION REGARDING STATUS OF MY SUBSCRIPTION FW: Auto-response for your message to the "Tutor" mailing list

2010-04-16 Thread Dave Angel
Peter Meagher wrote: GREETINGS, THIS EMAIL WOULD INDICATE THAT I AM ON THE SUBSCRIPTION LIST. HOWEVER, I GOT ANOTHER EMAIL, THAT CAME IN AT PRECISELY THE SAME TIME AS THE ORIGINAL MESSAGE THAT I AM FORWARDING YOU. THAT INDICATES THAT THERE WAS AN ISSUE ADDING ME TO THE LIST. I'VE PASTED IT IN T

Re: [Tutor] Loop comparison

2010-04-16 Thread Christian Witts
Dave Angel wrote: Christian Witts wrote: Ark wrote: Hi everyone. A friend of mine suggested me to do the next experiment in python and Java. It's a simple program to sum all the numbers from 0 to 10. result = i = 0 while i < 10: result += i i += 1 print result The

Re: [Tutor] Loop comparison

2010-04-16 Thread Christian Witts
Alan Gauld wrote: "Stefan Behnel" wrote import cython @cython.locals(result=cython.longlong, i=cython.longlong) def add(): result = 0 for i in xrange(10): result += i return result print add() This runs in less than half a second on

Re: [Tutor] Loop comparison

2010-04-16 Thread Stefan Behnel
Stefan Behnel, 16.04.2010 09:38: A compiler for a statically compiled language can see that the above loop yields a constant result, so it can calculate the result in advance (or at least reduce the loop overhead for the calculation) instead of generating code for the loop as it stands. That re

Re: [Tutor] Loop comparison

2010-04-16 Thread Dave Angel
Christian Witts wrote: Ark wrote: Hi everyone. A friend of mine suggested me to do the next experiment in python and Java. It's a simple program to sum all the numbers from 0 to 10. result = i = 0 while i < 10: result += i i += 1 print result The time for this calc

Re: [Tutor] Loop comparison

2010-04-16 Thread Alan Gauld
"Stefan Behnel" wrote import cython @cython.locals(result=cython.longlong, i=cython.longlong) def add(): result = 0 for i in xrange(10): result += i return result print add() This runs in less than half a second on my machine, inclu

Re: [Tutor] Loop comparison

2010-04-16 Thread Stefan Behnel
Alan Gauld, 16.04.2010 10:09: Even the built in sum() will be faster than a while loop: result = sum(range(10)) although it still took 10 minutes on my PC. Did you mean to say "minutes" or rather "seconds" here? And did you really mean to use "range" or rather "xrange" (or "range" in

Re: [Tutor] Loop comparison

2010-04-16 Thread Alan Gauld
"Ark" wrote It's a simple program to sum all the numbers from 0 to 10. result = i = 0 while i < 10: result += i i += 1 print result The time for this calculations was huge. It took a long time to give the result. But, the corresponding program in Java takes less than

[Tutor] QUESTION REGARDING STATUS OF MY SUBSCRIPTION FW: Auto-response for your message to the "Tutor" mailing list

2010-04-16 Thread Peter Meagher
GREETINGS, THIS EMAIL WOULD INDICATE THAT I AM ON THE SUBSCRIPTION LIST. HOWEVER, I GOT ANOTHER EMAIL, THAT CAME IN AT PRECISELY THE SAME TIME AS THE ORIGINAL MESSAGE THAT I AM FORWARDING YOU. THAT INDICATES THAT THERE WAS AN ISSUE ADDING ME TO THE LIST. I'VE PASTED IT IN THE BLOCK OF TEXT BELOW,

Re: [Tutor] Loop comparison

2010-04-16 Thread Christian Witts
Ark wrote: Hi everyone. A friend of mine suggested me to do the next experiment in python and Java. It's a simple program to sum all the numbers from 0 to 10. result = i = 0 while i < 10: result += i i += 1 print result The time for this calculations was huge. It took

Re: [Tutor] Loop comparison

2010-04-16 Thread Stefan Behnel
Ark, 16.04.2010 08:50: A friend of mine suggested me to do the next experiment in python and Java. It's a simple program to sum all the numbers from 0 to 10. result = i = 0 while i< 10: result += i i += 1 print result I hope you are aware that this is a) a very lous