You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Blair Zajac <bl...@orcaware.com> on 2009/10/27 03:52:06 UTC

Re: svn commit: r40229 - trunk/build

On Oct 26, 2009, at 8:38 PM, Bhuvaneswaran A wrote:

> Author: bhuvan
> Date: Mon Oct 26 20:38:19 2009
> New Revision: 40229
>
> Log:
> While running the test suite, even the microseconds are accountable.
>
> * build/run_tests.py
>  import datetime
>  (_run_test): Include microseconds while printing the time taken to
>  execute each test. Use datetime library instead of time library.
>
> Reviewed by: brane
>
> Modified:
>   trunk/build/run_tests.py
>
> Modified: trunk/build/run_tests.py
>
> import getopt
> try:
> @@ -206,7 +206,7 @@ class TestHarness:
>     log.write('START: %s\n' % progbase)
>     log.flush()
>
> -    start_time = time.time()
> +    start_time = datetime.now()
>     if progbase[-3:] == '.py':
>       progname = sys.executable
>       cmdline = [quote(progname),
> @@ -270,8 +270,7 @@ class TestHarness:
>         log.write('FAIL:  %s: Unknown test failure.\n' % progbase)
>
>     # Log the elapsed time.
> -    elapsed_time = time.strftime('%H:%M:%S',
> -                   time.gmtime(time.time() - start_time))
> +    elapsed_time = str(datetime.now() - start_time)

You don't need to put the value in str() since you're going to pass it  
to the % operator below for a %s interpolation, which calls str() on  
it already.

Regards,
Blair

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2411584

Re: svn commit: r40229 - trunk/build

Posted by Greg Stein <gs...@gmail.com>.
On Tue, Oct 27, 2009 at 00:14, Blair Zajac <bl...@orcaware.com> wrote:
> On Oct 26, 2009, at 9:08 PM, Branko Cibej wrote:
>
>> Blair Zajac wrote:
>>>
>>> On Oct 26, 2009, at 8:59 PM, Branko Cibej wrote:
>>>
>>>> Blair Zajac wrote:
>>>>>
>>>>>>   # Log the elapsed time.
>>>>>> -    elapsed_time = time.strftime('%H:%M:%S',
>>>>>> -                   time.gmtime(time.time() - start_time))
>>>>>> +    elapsed_time = str(datetime.now() - start_time)
>>>>>>
>>>>>
>>>>> You don't need to put the value in str() since you're going to
>>>>> pass it
>>>>> to the % operator below for a %s interpolation, which calls str()
>>>>> on
>>>>> it already.
>>>>>
>>>>
>>>> No, he doesn't need to. But there shouldn't be any discernible
>>>> difference between calling str() here explicitly, and letting the
>>>> formatter do that later, implicitly. This way it's at least clear
>>>> what's
>>>> going on. I do remember reading somewhere that "explicit is better
>>>> than
>>>> implicit." :)
>>>
>>> It is a tiny bit wasteful, since there will be another str() called
>>> on
>>> elapsed_time.
>>
>> I don't think I want to look at the Python sources to see if it skips
>> calling str() for string arguments. :)
>>
>>> Also, it's an integer value and maybe later you want to add those
>>> elapsed times (I'm just making this up), so it's possible you'll
>>> remove the str() later.
>>>
>>> Do you always convert something to a string if you the only thing
>>> you're going to do is print it?
>>>
>>> Also, I don't think this is clearer, keeping an int and printing it
>>> is
>>> pretty clear :)
>>
>> Well of course it's not an int, it's a datetime.timedelta, otherwise a
>> %d formatter would be more appropriate, no?
>
> Well, ok, I should have checked that it's not an in int :)
>
> This is descending to the level of I don't care, but out of curiosity,
> does anybody take the time to use non-%s for string interpolation?
> The code I write and most of the code I see doesn't bother to use non-
> %s unless special formatting is needed, say %10.5f.

Same here. %s always works, so I roll with it.

>> I'll have the mauve with vermillion spots, please.
>
> Ditto.

You peasants. Anybody who knows anything will tell you to get the
lavender with rose stripes.

Cheers,
-g

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2411653

Re: svn commit: r40229 - trunk/build

Posted by Branko Cibej <br...@xbc.nu>.
Blair Zajac wrote:
> This is descending to the level of I don't care, but out of curiosity,
> does anybody take the time to use non-%s for string interpolation? 
> The code I write and most of the code I see doesn't bother to use
> non-%s unless special formatting is needed, say %10.5f.

I may be a conservative, crotchety old C programmer, but I tend to be
quite pedantic about formatting. Especially in a weakly-typed language
like Python, where the formatter at least yells at you if you happen to,
e.g., send a timedelta to a %d instead of an int. Using a %s always
"works" but also hides bugs.

-- Brane

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2411619

Re: svn commit: r40229 - trunk/build

Posted by Blair Zajac <bl...@orcaware.com>.
On Oct 26, 2009, at 9:08 PM, Branko Cibej wrote:

> Blair Zajac wrote:
>>
>> On Oct 26, 2009, at 8:59 PM, Branko Cibej wrote:
>>
>>> Blair Zajac wrote:
>>>>
>>>>>   # Log the elapsed time.
>>>>> -    elapsed_time = time.strftime('%H:%M:%S',
>>>>> -                   time.gmtime(time.time() - start_time))
>>>>> +    elapsed_time = str(datetime.now() - start_time)
>>>>>
>>>>
>>>> You don't need to put the value in str() since you're going to  
>>>> pass it
>>>> to the % operator below for a %s interpolation, which calls str()  
>>>> on
>>>> it already.
>>>>
>>>
>>> No, he doesn't need to. But there shouldn't be any discernible
>>> difference between calling str() here explicitly, and letting the
>>> formatter do that later, implicitly. This way it's at least clear  
>>> what's
>>> going on. I do remember reading somewhere that "explicit is better  
>>> than
>>> implicit." :)
>>
>> It is a tiny bit wasteful, since there will be another str() called  
>> on
>> elapsed_time.
>
> I don't think I want to look at the Python sources to see if it skips
> calling str() for string arguments. :)
>
>> Also, it's an integer value and maybe later you want to add those
>> elapsed times (I'm just making this up), so it's possible you'll
>> remove the str() later.
>>
>> Do you always convert something to a string if you the only thing
>> you're going to do is print it?
>>
>> Also, I don't think this is clearer, keeping an int and printing it  
>> is
>> pretty clear :)
>
> Well of course it's not an int, it's a datetime.timedelta, otherwise a
> %d formatter would be more appropriate, no?

Well, ok, I should have checked that it's not an in int :)

This is descending to the level of I don't care, but out of curiosity,  
does anybody take the time to use non-%s for string interpolation?   
The code I write and most of the code I see doesn't bother to use non- 
%s unless special formatting is needed, say %10.5f.

> I'll have the mauve with vermillion spots, please.

Ditto.

Blair

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2411591

Re: svn commit: r40229 - trunk/build

Posted by Branko Cibej <br...@xbc.nu>.
Blair Zajac wrote:
>
> On Oct 26, 2009, at 8:59 PM, Branko Cibej wrote:
>
>> Blair Zajac wrote:
>>>
>>>>    # Log the elapsed time.
>>>> -    elapsed_time = time.strftime('%H:%M:%S',
>>>> -                   time.gmtime(time.time() - start_time))
>>>> +    elapsed_time = str(datetime.now() - start_time)
>>>>
>>>
>>> You don't need to put the value in str() since you're going to pass it
>>> to the % operator below for a %s interpolation, which calls str() on
>>> it already.
>>>
>>
>> No, he doesn't need to. But there shouldn't be any discernible
>> difference between calling str() here explicitly, and letting the
>> formatter do that later, implicitly. This way it's at least clear what's
>> going on. I do remember reading somewhere that "explicit is better than
>> implicit." :)
>
> It is a tiny bit wasteful, since there will be another str() called on
> elapsed_time.

I don't think I want to look at the Python sources to see if it skips
calling str() for string arguments. :)

> Also, it's an integer value and maybe later you want to add those
> elapsed times (I'm just making this up), so it's possible you'll
> remove the str() later.
>
> Do you always convert something to a string if you the only thing
> you're going to do is print it?
>
> Also, I don't think this is clearer, keeping an int and printing it is
> pretty clear :)

Well of course it's not an int, it's a datetime.timedelta, otherwise a
%d formatter would be more appropriate, no?

I'll have the mauve with vermillion spots, please.

-- Brane

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2411589

Re: svn commit: r40229 - trunk/build

Posted by Blair Zajac <bl...@orcaware.com>.
On Oct 26, 2009, at 8:59 PM, Branko Cibej wrote:

> Blair Zajac wrote:
>>
>>>    # Log the elapsed time.
>>> -    elapsed_time = time.strftime('%H:%M:%S',
>>> -                   time.gmtime(time.time() - start_time))
>>> +    elapsed_time = str(datetime.now() - start_time)
>>>
>>
>> You don't need to put the value in str() since you're going to pass  
>> it
>> to the % operator below for a %s interpolation, which calls str() on
>> it already.
>>
>
> No, he doesn't need to. But there shouldn't be any discernible
> difference between calling str() here explicitly, and letting the
> formatter do that later, implicitly. This way it's at least clear  
> what's
> going on. I do remember reading somewhere that "explicit is better  
> than
> implicit." :)

It is a tiny bit wasteful, since there will be another str() called on  
elapsed_time.  Also, it's an integer value and maybe later you want to  
add those elapsed times (I'm just making this up), so it's possible  
you'll remove the str() later.

Do you always convert something to a string if you the only thing  
you're going to do is print it?

Also, I don't think this is clearer, keeping an int and printing it is  
pretty clear :)

Blair

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2411588

Re: svn commit: r40229 - trunk/build

Posted by Branko Cibej <br...@xbc.nu>.
Blair Zajac wrote:
>
>>     # Log the elapsed time.
>> -    elapsed_time = time.strftime('%H:%M:%S',
>> -                   time.gmtime(time.time() - start_time))
>> +    elapsed_time = str(datetime.now() - start_time)
>>     
>
> You don't need to put the value in str() since you're going to pass it  
> to the % operator below for a %s interpolation, which calls str() on  
> it already.
>   

No, he doesn't need to. But there shouldn't be any discernible
difference between calling str() here explicitly, and letting the
formatter do that later, implicitly. This way it's at least clear what's
going on. I do remember reading somewhere that "explicit is better than
implicit." :)

-- Brane

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2411586