Re: [go-nuts] Re: golang time.Now().Format with milliseconds without dot in string

2020-07-19 Thread peterGo
Vasiliy Tolstov,

"I need to output strings with format MMDDHHMMSSMILLISEC without dot in 
string. But Go able to output milliseconds only in case of .000" ... "that 
works with many messages and want to avoid additional memory allocations"

The Go standard library does not pretend to provide everything you might 
need. Sometimes you need to do some programming. For example,

func formatMillisecond(t time.Time) string

fmtms.go
https://play.golang.org/p/dfackUTL9qw

$ go run fmtms.go

2009111023.001
2009111023001

A specialized function is often faster that a generalized function.

fmtms_test.go
https://play.golang.org/p/wS7PqZjExDq

$ go test fmtms_test.go fmtms.go -bench=. -benchmem

BenchmarkFmtMs-4   11470974   101 ns/op   32 B/op   1 allocs/op
BenchmarkNoDot-44385608   272 ns/op   64 B/op   2 allocs/op
BenchmarkDot-4  5529204   215 ns/op   32 B/op   1 allocs/op

Peter


On Saturday, July 18, 2020 at 6:49:23 PM UTC-4, Vasiliy Tolstov wrote:
>
> пт, 17 июл. 2020 г. в 05:40, Justin Israel  >: 
> > 
> > 
> > 
> > On Friday, July 17, 2020 at 11:21:32 AM UTC+12 va...@selfip.ru wrote: 
> >> 
> >> вт, 14 июл. 2020 г. в 18:39, Jake Montgomery : 
> >> > 
> >> > I agree, it seems like an unfortunate oversight. You can do it 
> without the slice tricks: https://play.golang.org/p/tNAPOcQqApN 
> >> > It does take an additional Sprintf() though. 
> >> > 
> >> 
> >> Thanks, looks good. But i think for go devs adding additional format 
> >> that can be used to specify milli/micro/nano seconds will be easy. 
> >> 
> >> -- 
> >> Vasiliy Tolstov, 
> >> e-mail: v.to...@selfip.ru 
> > 
> > 
> > I asked the same question on reddit about a month ago, where I needed to 
> match an existing timestamp format: 
> > 
> https://www.reddit.com/r/golang/comments/gr7hz9/string_formatting_a_timetime_with_custom/
>  
> > 
> > Seems string formatting was the best option available to me. 
> > 
>
> Yes, this is bad case for stuff that works with many messages and 
> want to avoid additional memory allocations 
>
> -- 
> Vasiliy Tolstov, 
> e-mail: v.to...@selfip.ru  
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e837d235-0227-49f5-97f8-738a6bf7d3ebo%40googlegroups.com.


Re: [go-nuts] Re: golang time.Now().Format with milliseconds without dot in string

2020-07-18 Thread Vasiliy Tolstov
пт, 17 июл. 2020 г. в 05:40, Justin Israel :
>
>
>
> On Friday, July 17, 2020 at 11:21:32 AM UTC+12 va...@selfip.ru wrote:
>>
>> вт, 14 июл. 2020 г. в 18:39, Jake Montgomery :
>> >
>> > I agree, it seems like an unfortunate oversight. You can do it without the 
>> > slice tricks: https://play.golang.org/p/tNAPOcQqApN
>> > It does take an additional Sprintf() though.
>> >
>>
>> Thanks, looks good. But i think for go devs adding additional format
>> that can be used to specify milli/micro/nano seconds will be easy.
>>
>> --
>> Vasiliy Tolstov,
>> e-mail: v.to...@selfip.ru
>
>
> I asked the same question on reddit about a month ago, where I needed to 
> match an existing timestamp format:
> https://www.reddit.com/r/golang/comments/gr7hz9/string_formatting_a_timetime_with_custom/
>
> Seems string formatting was the best option available to me.
>

Yes, this is bad case for stuff that works with many messages and
want to avoid additional memory allocations

-- 
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CACaajQtAFAkmr9U2JY14b7Cie2i%2B_w9Oc1d7GiOXgchEaH_bog%40mail.gmail.com.


Re: [go-nuts] Re: golang time.Now().Format with milliseconds without dot in string

2020-07-16 Thread Justin Israel


On Friday, July 17, 2020 at 11:21:32 AM UTC+12 va...@selfip.ru wrote:

> вт, 14 июл. 2020 г. в 18:39, Jake Montgomery : 
> > 
> > I agree, it seems like an unfortunate oversight. You can do it without 
> the slice tricks: https://play.golang.org/p/tNAPOcQqApN 
> > It does take an additional Sprintf() though. 
> > 
>
> Thanks, looks good. But i think for go devs adding additional format 
> that can be used to specify milli/micro/nano seconds will be easy. 
>
> -- 
> Vasiliy Tolstov, 
> e-mail: v.to...@selfip.ru 
>

I asked the same question on reddit about a month ago, where I needed to 
match an existing timestamp format:
https://www.reddit.com/r/golang/comments/gr7hz9/string_formatting_a_timetime_with_custom/

Seems string formatting was the best option available to me.
 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5b132613-5be4-4062-8092-5e0cfa92a7d6n%40googlegroups.com.


Re: [go-nuts] Re: golang time.Now().Format with milliseconds without dot in string

2020-07-16 Thread Vasiliy Tolstov
вт, 14 июл. 2020 г. в 18:39, Jake Montgomery :
>
> I agree, it seems like an unfortunate oversight. You can do it without the 
> slice tricks: https://play.golang.org/p/tNAPOcQqApN
> It does take an additional Sprintf() though.
>

Thanks, looks good. But i think for go devs adding additional format
that can be used to specify milli/micro/nano seconds will be easy.

-- 
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CACaajQu97PQt_OZLM8NmAqv998Bi-8N0PzvAQuRsGXDthsuB3Q%40mail.gmail.com.


Re: [go-nuts] Re: golang time.Now().Format with milliseconds without dot in string

2020-07-14 Thread Jake Montgomery
I agree, it seems like an unfortunate oversight. You can do it without the 
slice tricks: https://play.golang.org/p/tNAPOcQqApN
It does take an additional Sprintf() though.

On Tuesday, July 14, 2020 at 8:40:18 AM UTC-4, Vasiliy Tolstov wrote:
>
> вт, 14 июл. 2020 г. в 15:17, Jake Montgomery  >: 
> > 
> > Why not just remove the dot? You know where it is: 
> https://play.golang.org/p/ZHqHTOeA7HQ 
> > Perhaps there is a better way, but this seems to work. 
> > 
>
> Yes, thanks. My question mostly - why format time to some intermediate 
> string that needs to be preprocessed before usage =) 
> Format means that you get a needed sting and not that you must use 
> slice manipulation. 
>
> -- 
> Vasiliy Tolstov, 
> e-mail: v.to...@selfip.ru  
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/a96b94bc-ab09-488f-9a7a-5622e6935a1eo%40googlegroups.com.


Re: [go-nuts] Re: golang time.Now().Format with milliseconds without dot in string

2020-07-14 Thread Vasiliy Tolstov
вт, 14 июл. 2020 г. в 15:17, Jake Montgomery :
>
> Why not just remove the dot? You know where it is: 
> https://play.golang.org/p/ZHqHTOeA7HQ
> Perhaps there is a better way, but this seems to work.
>

Yes, thanks. My question mostly - why format time to some intermediate
string that needs to be preprocessed before usage =)
Format means that you get a needed sting and not that you must use
slice manipulation.

-- 
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CACaajQvgos6dd2B-kH-S7JKbDvFU7cVopOZYDAsEQH1TU1av_A%40mail.gmail.com.