[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: When is multiple assignment good style?
- From: Sean Conner <sean@...>
- Date: Thu, 16 Mar 2017 15:22:43 -0400
It was thus said that the Great Martin once stated:
> On 03/16/2017 10:39 AM, Sean Conner wrote:
> > This reminded me of this blog post from James Hague: http://prog21.dadgum.com/52.html
> >
> > The sieve in Atari BASIC, using timings from an article written in
> > 1984 by Brian Moriarty, clocks in at:
> >
> > 324 seconds (or just under 5 and a half minutes)
> >
> > The Python version, running on hardware that's a generation back--no
> > i7 processor or anything like that--completes in:
> >
> > 3 seconds
> >
> > Now that's impressive! A straight-ahead interpreted language, one
> > with garbage collection and dynamic typing and memory allocation all
> > over the place, and it's still two orders of magnitude, 108 times,
> > faster than what hobbyist programmers had to work with twenty-five
> > years ago.
> >
> > Read the rest for the actual punchline.
> >
> > -spc (Who's first computer wasn't even a full 1 MHz in speed)
>
> Didn't get the point.
Ditto.
The original benchmark showed a difference of .1 seconds. No mention of
CPU speed, nor number of tests. If .1s was the difference between one call
to table.insert vs. tinsert then yes, there is an issue. If .1s is the
difference between a million calls to table.insert() vs. tinsert, then maybe
not so much (unless you really are doing a million sustained table.inserts()
per second, and then, how much memory do you have?).
I ran the following bit of code:
local gettime = require "org.conman.clock".get [1]
local tinst = table.insert
local trem = table.remove
local t = { 1 , 2 , 3 , 4 }
local zen = gettime('monotonic')
for i = 1 , 1000000 do
table.remove(t)
table.insert(t,4)
end
local now = gettime('monotonic')
local d1 = now - zen
print(d1)
local zen = gettime('monotonic')
for i = 1 , 1000000 do
trem(t)
tinst(t,4)
end
local now = gettime('monotonic')
local d2 = now - zen
print(d2)
print(d1-d2)
and I ran it on two different machines---A 32 bit Linux running at 2.6GHz,
and a 64-bit Linux system running at 2.8GHz:
32-bit version:
[spc]lucy:/tmp>lua xx.lua
0.58142000017688
0.47776100016199
0.10365900001489
64-bit version:
[spc]saltmine-2:/tmp>lua xx.lua
0.24713175185025
0.17022603750229
0.076905714347959
For me, that's close enough for the work I do [2]. If my program does have
a performance issue, I'll profile and then fix what's slow (which probably
isn't table.insert() vs. tinsert()).
-spc
[1] https://github.com/spc476/lua-conmanorg/blob/master/src/clock.c
[2] Processing SIP messages for a major telephone company
- References:
- When is multiple assignment good style?, Dirk Laurie
- Re: When is multiple assignment good style?, Sean Conner
- Re: When is multiple assignment good style?, Tim Hill
- Re: When is multiple assignment good style?, Coda Highland
- Re: When is multiple assignment good style?, Hisham
- Re: When is multiple assignment good style?, Chris Jones
- Re: When is multiple assignment good style?, Soni L.
- Re: When is multiple assignment good style?, Chris Jones
- Re: When is multiple assignment good style?, Sean Conner
- Re: When is multiple assignment good style?, Martin