#std.mem.concat vs std.fmt.allocPrint?

1 messages · Page 1 of 1 (latest)

honest hill
#

Is it faster/better to use std.mem.concat when using only strings in a std.fmt.allocPrint? Or does it mostly depend on whats more readable?

lyric gazelle
#

concat is probably faster

#

because it doesn't us the format logic

#

and it doesn't require to use std.fmt.count on it

honest hill
#

yea that's what i was suspecting, thanks for confirming

#

wasnt sure if there was some sort of optimization to force it to use concat

dawn shale
#

just out of curiosity i did a couple tiny tests, its using fixedbufferallocator so probably not very representative but at the same time probably as optimal as the asm will get

main.main:
    sub    $0xa8,%rsp
    vmovaps -0xa51f(%rip),%xmm0       ; 0x200240
    vmovaps %xmm0,-0x60(%rsp)
    movabs $0x68746e6576656c65,%rax
    mov    %rax,-0x50(%rsp)
    int3
    lea    -0x60(%rsp),%rax
    mov    %rax,-0x70(%rsp)
    movq   $0x18,-0x68(%rsp)
    lea    -0x70(%rsp),%rax
    mov    %rax,-0x78(%rsp)
    add    $0xa8,%rsp
    ret
main.main:
    push   %rbx
    sub    $0x130,%rsp
    lea    0x30(%rsp),%rax
    mov    %rax,0x10(%rsp)
    movq   $0x18,0x18(%rsp)
    movq   $0x0,0x20(%rsp)
    lea    0x10(%rsp),%rbx
    mov    %rbx,0x8(%rsp)
    lea    0x8(%rsp),%rcx
    mov    $0x208c01,%edi
    mov    $0x5,%esi
    mov    $0x207e70,%edx
    call   0x20ae90                   ; <fmt.formatBuf__anon_4124>
    test   %ax,%ax
    jne    0x20a7a6                   ; <main.main+166>
    lea    0x8(%rsp),%rcx
    mov    $0x2092a8,%edi
    mov    $0x6,%esi
    mov    $0x207e70,%edx
    call   0x20ae90                   ; <fmt.formatBuf__anon_4124>
    test   %ax,%ax
    jne    0x20a7a6                   ; <main.main+166>
    lea    0x8(%rsp),%rcx
    mov    $0x209295,%edi
    mov    $0x5,%esi
    mov    $0x207e70,%edx
    call   0x20ae90                   ; <fmt.formatBuf__anon_4124>
    test   %ax,%ax
    jne    0x20a7a6                   ; <main.main+166>
    lea    0x8(%rsp),%rcx
    mov    $0x208f5e,%edi
    mov    $0x8,%esi
    mov    $0x207e70,%edx
    call   0x20ae90                   ; <fmt.formatBuf__anon_4124>
    test   %ax,%ax
    je     0x20a7bf                   ; <main.main+191>
    int3
    mov    %rax,0x10(%rsp)
    mov    %rcx,0x18(%rsp)
    mov    %rbx,0x28(%rsp)
    add    $0x130,%rsp
    pop    %rbx
    ret
    mov    0x10(%rsp),%rax
    mov    0x20(%rsp),%rcx
    jmp    0x20a7a6                   ; <main.main+166>
#

first is concat, second is allocPrint