[ANN] ZTimestamp

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[ANN] ZTimestamp

Sven Van Caekenberghe
We have DateAndTime and TimeStamp, which are generally useful objects with lots of features.

But for a lot of applications, they are too heavy. In server side code, timestamps are almost always in UTC (timezone zero). In most cases, nanosecond or millisecond precision are not (really) needed. Unix/Posix time has only second precision.

I wrote ZTimestamp as an alternative for DateAndTime and TimeStamp.
It has second precision and lives in the UTC/GMT/Zulu timezone.
It uses ISO/International conventions and protocols only.
ZTimestamp is more efficient: it uses half the memory of DateAndTime and is faster.

You can find it in

        http://mc.stfx.eu/Neo

ConfigurationOfZTimestamp is also available from

        http://www.squeaksource.com/MetacelloRepository
        http://squeaksource.com/MetaRepoForPharo14
        http://ss3.gemstone.com/ss/MetaRepoForPharo20

Here are some benchmarks:

[ 1000 timesRepeat: [ ZTimestamp now ] ] bench '1,910 per second.'
[ 1000 timesRepeat: [ DateAndTime now ] ] bench '253 per second.'

[ 1000 timesRepeat: [ ZTimestamp fromString: '2012-06-18T07:51:40Z' ] ] bench '161 per second.'
[ 1000 timesRepeat: [ DateAndTime fromString: '2012-06-18T07:51:40Z' ] ] bench '44.9 per second.'

[ 1000 timesRepeat: [ ZTimestamp now printString ] ] bench '212 per second.'
[ 1000 timesRepeat: [ DateAndTime now printString ] ] bench '82.3 per second.'
[ 1000 timesRepeat: [ TimeStamp now printString ] ] bench '54.2 per second.'


[ 1000 timesRepeat: [ (ZTimestamp fromUnixTime: 1340006939) = (ZTimestamp fromUnixTime: 2540006939) ] ] bench '377 per second.'
[ 1000 timesRepeat: [ (DateAndTime fromUnixTime: 1340006939) = (DateAndTime fromUnixTime: 2540006939) ] ] bench '142 per second.'

[ 1000 timesRepeat: [ (ZTimestamp fromUnixTime: 1340006939) < (ZTimestamp fromUnixTime: 2540006939) ] ] bench '376 per second.'
[ 1000 timesRepeat: [ (DateAndTime fromUnixTime: 1340006939) < (DateAndTime fromUnixTime: 2540006939) ] ] bench '134 per second.'

[ 1000 timesRepeat: [ (ZTimestamp fromUnixTime: 1340006939) + 10 days ] ] bench '604 per second.'
[ 1000 timesRepeat: [ (DateAndTime fromUnixTime: 1340006939) + 10 days ] ] bench '142 per second.'

[ 1000 timesRepeat: [ (ZTimestamp fromUnixTime: 1340006939) - (ZTimestamp fromUnixTime: 2540006939) ] ] bench '239 per second.'
[ 1000 timesRepeat: [ (DateAndTime fromUnixTime: 1340006939) - (DateAndTime fromUnixTime: 2540006939) ] ] bench '98.8 per second.'


[ 1000 timesRepeat: [ (ZTimestamp year: 2012 month: 7 day: 1 hour: 8 minute: 8 second: 8) = (ZTimestamp year: 2011 month: 5 day: 2 hour: 4 minute: 4 second: 4) ] ] bench '2,040 per second.'
[ 1000 timesRepeat: [ (DateAndTime year: 2012 month: 7 day: 1 hour: 8 minute: 8 second: 8) = (DateAndTime year: 2011 month: 5 day: 2 hour: 4 minute: 4 second: 4) ] ] bench '1,800 per second.'

[ 1000 timesRepeat: [ (ZTimestamp year: 2012 month: 7 day: 1 hour: 8 minute: 8 second: 8) < (ZTimestamp year: 2011 month: 5 day: 2 hour: 4 minute: 4 second: 4) ] ] bench '2,220 per second.'
[ 1000 timesRepeat: [ (DateAndTime year: 2012 month: 7 day: 1 hour: 8 minute: 8 second: 8) < (DateAndTime year: 2011 month: 5 day: 2 hour: 4 minute: 4 second: 4) ] ] bench '1,050 per second.'

[ 1000 timesRepeat: [ (ZTimestamp year: 2012 month: 7 day: 1 hour: 8 minute: 8 second: 8) + 10 days ] ] bench '1,970 per second.'
[ 1000 timesRepeat: [ (DateAndTime year: 2012 month: 7 day: 1 hour: 8 minute: 8 second: 8) + 10 days ] ] bench '245 per second.'

[ 1000 timesRepeat: [ (ZTimestamp year: 2012 month: 7 day: 1 hour: 8 minute: 8 second: 8) - (ZTimestamp year: 2011 month: 5 day: 2 hour: 4 minute: 4 second: 4) ] ] bench '1,440 per second.'
[ 1000 timesRepeat: [ (DateAndTime year: 2012 month: 7 day: 1 hour: 8 minute: 8 second: 8) - (DateAndTime year: 2011 month: 5 day: 2 hour: 4 minute: 4 second: 4) ] ] bench '767 per second.'


ZTimestamp is *not* meant as a general replacement for DateAndTime or TimeStamp. But in a lot of cases, it can be more efficient.

Feedback and users are welcome.


Sven


--
Sven Van Caekenberghe
http://stfx.eu
Smalltalk is the Red Pill





Reply | Threaded
Open this post in threaded view
|

Re: [ANN] ZTimestamp

Igor Stasenko
On 22 June 2012 20:46, Sven Van Caekenberghe <[hidden email]> wrote:

> We have DateAndTime and TimeStamp, which are generally useful objects with lots of features.
>
> But for a lot of applications, they are too heavy. In server side code, timestamps are almost always in UTC (timezone zero). In most cases, nanosecond or millisecond precision are not (really) needed. Unix/Posix time has only second precision.
>
> I wrote ZTimestamp as an alternative for DateAndTime and TimeStamp.
> It has second precision and lives in the UTC/GMT/Zulu timezone.
> It uses ISO/International conventions and protocols only.
> ZTimestamp is more efficient: it uses half the memory of DateAndTime and is faster.
>
> You can find it in
>
>        http://mc.stfx.eu/Neo
>
> ConfigurationOfZTimestamp is also available from
>
>        http://www.squeaksource.com/MetacelloRepository
>        http://squeaksource.com/MetaRepoForPharo14
>        http://ss3.gemstone.com/ss/MetaRepoForPharo20
>
> Here are some benchmarks:
>
> [ 1000 timesRepeat: [ ZTimestamp now ] ] bench '1,910 per second.'
> [ 1000 timesRepeat: [ DateAndTime now ] ] bench '253 per second.'

what? 253 per second? what it doing there?

>
> [ 1000 timesRepeat: [ ZTimestamp fromString: '2012-06-18T07:51:40Z' ] ] bench '161 per second.'
> [ 1000 timesRepeat: [ DateAndTime fromString: '2012-06-18T07:51:40Z' ] ] bench '44.9 per second.'
>
> [ 1000 timesRepeat: [ ZTimestamp now printString ] ] bench '212 per second.'
> [ 1000 timesRepeat: [ DateAndTime now printString ] ] bench '82.3 per second.'
> [ 1000 timesRepeat: [ TimeStamp now printString ] ] bench '54.2 per second.'
>
>
> [ 1000 timesRepeat: [ (ZTimestamp fromUnixTime: 1340006939) = (ZTimestamp fromUnixTime: 2540006939) ] ] bench '377 per second.'
> [ 1000 timesRepeat: [ (DateAndTime fromUnixTime: 1340006939) = (DateAndTime fromUnixTime: 2540006939) ] ] bench '142 per second.'
>
> [ 1000 timesRepeat: [ (ZTimestamp fromUnixTime: 1340006939) < (ZTimestamp fromUnixTime: 2540006939) ] ] bench '376 per second.'
> [ 1000 timesRepeat: [ (DateAndTime fromUnixTime: 1340006939) < (DateAndTime fromUnixTime: 2540006939) ] ] bench '134 per second.'
>
> [ 1000 timesRepeat: [ (ZTimestamp fromUnixTime: 1340006939) + 10 days ] ] bench '604 per second.'
> [ 1000 timesRepeat: [ (DateAndTime fromUnixTime: 1340006939) + 10 days ] ] bench '142 per second.'
>
> [ 1000 timesRepeat: [ (ZTimestamp fromUnixTime: 1340006939) - (ZTimestamp fromUnixTime: 2540006939) ] ] bench '239 per second.'
> [ 1000 timesRepeat: [ (DateAndTime fromUnixTime: 1340006939) - (DateAndTime fromUnixTime: 2540006939) ] ] bench '98.8 per second.'
>
>
> [ 1000 timesRepeat: [ (ZTimestamp year: 2012 month: 7 day: 1 hour: 8 minute: 8 second: 8) = (ZTimestamp year: 2011 month: 5 day: 2 hour: 4 minute: 4 second: 4) ] ] bench '2,040 per second.'
> [ 1000 timesRepeat: [ (DateAndTime year: 2012 month: 7 day: 1 hour: 8 minute: 8 second: 8) = (DateAndTime year: 2011 month: 5 day: 2 hour: 4 minute: 4 second: 4) ] ] bench '1,800 per second.'
>
> [ 1000 timesRepeat: [ (ZTimestamp year: 2012 month: 7 day: 1 hour: 8 minute: 8 second: 8) < (ZTimestamp year: 2011 month: 5 day: 2 hour: 4 minute: 4 second: 4) ] ] bench '2,220 per second.'
> [ 1000 timesRepeat: [ (DateAndTime year: 2012 month: 7 day: 1 hour: 8 minute: 8 second: 8) < (DateAndTime year: 2011 month: 5 day: 2 hour: 4 minute: 4 second: 4) ] ] bench '1,050 per second.'
>
> [ 1000 timesRepeat: [ (ZTimestamp year: 2012 month: 7 day: 1 hour: 8 minute: 8 second: 8) + 10 days ] ] bench '1,970 per second.'
> [ 1000 timesRepeat: [ (DateAndTime year: 2012 month: 7 day: 1 hour: 8 minute: 8 second: 8) + 10 days ] ] bench '245 per second.'
>
> [ 1000 timesRepeat: [ (ZTimestamp year: 2012 month: 7 day: 1 hour: 8 minute: 8 second: 8) - (ZTimestamp year: 2011 month: 5 day: 2 hour: 4 minute: 4 second: 4) ] ] bench '1,440 per second.'
> [ 1000 timesRepeat: [ (DateAndTime year: 2012 month: 7 day: 1 hour: 8 minute: 8 second: 8) - (DateAndTime year: 2011 month: 5 day: 2 hour: 4 minute: 4 second: 4) ] ] bench '767 per second.'
>
>
> ZTimestamp is *not* meant as a general replacement for DateAndTime or TimeStamp. But in a lot of cases, it can be more efficient.
>
> Feedback and users are welcome.
>
>
> Sven
>
>
> --
> Sven Van Caekenberghe
> http://stfx.eu
> Smalltalk is the Red Pill
>
>
>
>
>



--
Best regards,
Igor Stasenko.

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] ZTimestamp

Paul DeBruicker
On 06/22/2012 01:11 PM, Igor Stasenko wrote:
>> >Here are some benchmarks:
>> >
>> >[ 1000 timesRepeat: [ ZTimestamp now ] ] bench '1,910 per second.'
>> >[ 1000 timesRepeat: [ DateAndTime now ] ] bench '253 per second.'
> what? 253 per second? what it doing there?
>

253 iterations of 1000 timesRepeat:[DateAndTime now] per second.

So ~253,000 iterations of DateAndTime now per second.

[DateAndTime now] bench






Reply | Threaded
Open this post in threaded view
|

Re: [ANN] ZTimestamp

Sven Van Caekenberghe

On 22 Jun 2012, at 22:23, Paul DeBruicker wrote:

> On 06/22/2012 01:11 PM, Igor Stasenko wrote:
>>> >Here are some benchmarks:
>>> >
>>> >[ 1000 timesRepeat: [ ZTimestamp now ] ] bench '1,910 per second.'
>>> >[ 1000 timesRepeat: [ DateAndTime now ] ] bench '253 per second.'
>> what? 253 per second? what it doing there?
>>
>
> 253 iterations of 1000 timesRepeat:[DateAndTime now] per second.
>
> So ~253,000 iterations of DateAndTime now per second.
>
> [DateAndTime now] bench

Yes, depending on the use case one can discuss about the absolute numbers.

But consider a LRU style cache where on each operation the timestamp is updated to now, you'll want speed, right ?

Sven
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] ZTimestamp

Paul DeBruicker
Yes I agree there's a need for speed.  I think ZnTimestamp is a valuable addition.

And maybe the primitive that returns ms since epoch and offset gets adopted so DateAndTime can be nearly as fast.



On Jun 22, 2012, at 2:51 PM, Sven Van Caekenberghe <[hidden email]> wrote:

>
> On 22 Jun 2012, at 22:23, Paul DeBruicker wrote:
>
>> On 06/22/2012 01:11 PM, Igor Stasenko wrote:
>>>>> Here are some benchmarks:
>>>>>
>>>>> [ 1000 timesRepeat: [ ZTimestamp now ] ] bench '1,910 per second.'
>>>>> [ 1000 timesRepeat: [ DateAndTime now ] ] bench '253 per second.'
>>> what? 253 per second? what it doing there?
>>>
>>
>> 253 iterations of 1000 timesRepeat:[DateAndTime now] per second.
>>
>> So ~253,000 iterations of DateAndTime now per second.
>>
>> [DateAndTime now] bench
>
> Yes, depending on the use case one can discuss about the absolute numbers.
>
> But consider a LRU style cache where on each operation the timestamp is updated to now, you'll want speed, right ?
>
> Sven

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] ZTimestamp

LogiqueWerks
There are so very many practical cases where this lighter Zt will be useful.

It just goes nicely with don't build what you won't use.

Inserting time into generated web page meta content is one; fast
"bookmarks" is another (with offset UTC set to hard-coded -00:00 )

R

On 22 June 2012 19:14, Paul DeBruicker <[hidden email]> wrote:

> Yes I agree there's a need for speed.  I think ZnTimestamp is a valuable addition.
>
> And maybe the primitive that returns ms since epoch and offset gets adopted so DateAndTime can be nearly as fast.
>
>
>
> On Jun 22, 2012, at 2:51 PM, Sven Van Caekenberghe <[hidden email]> wrote:
>
>>
>> On 22 Jun 2012, at 22:23, Paul DeBruicker wrote:
>>
>>> On 06/22/2012 01:11 PM, Igor Stasenko wrote:
>>>>>> Here are some benchmarks:
>>>>>>
>>>>>> [ 1000 timesRepeat: [ ZTimestamp now ] ] bench '1,910 per second.'
>>>>>> [ 1000 timesRepeat: [ DateAndTime now ] ] bench '253 per second.'
>>>> what? 253 per second? what it doing there?
>>>>
>>>
>>> 253 iterations of 1000 timesRepeat:[DateAndTime now] per second.
>>>
>>> So ~253,000 iterations of DateAndTime now per second.
>>>
>>> [DateAndTime now] bench
>>
>> Yes, depending on the use case one can discuss about the absolute numbers.
>>
>> But consider a LRU style cache where on each operation the timestamp is updated to now, you'll want speed, right ?
>>
>> Sven
>