flat assembler
Message board for the users of flat assembler.

Index > Main > dword to ascii, ascii to dword

Goto page Previous  1, 2, 3, 4
Author
Thread Post new topic Reply to topic
sleepsleep



Joined: 05 Oct 2006
Posts: 9130
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
AsmGuru62 wrote:
I will still post my code, even if it will be slow.


yeah, that attitude is what we all want Smile

this isn,t all about code, it is about ARTS,

the live we gave into digital through our imagination,
perhaps some thousand ways to solve it, each got their own ART, like how to oil paint a picture.

i guess my code is the slowest among all, but i dont think that is a problem Laughing

ok guys, please submit your code, i will use that QWORD api today, and we see how fast you guys could drive Cool and that is AWESOME if you ask me.
Post 14 Feb 2013, 09:53
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1419
Location: Toronto, Canada
AsmGuru62
I wrote the test and I see very different results.
Fascinating! -- as Mr. Spock would say.
The same code runs and produces results in range from around 7000 counts (for 1000 strings converted)
to around 9000 counts.
So, there is a difference in 2000 counts from time to time.
I think it happens because the other tasks (I test on Windows) are
preempting the function I am calling. Like all kind of services, etc.
These things are running all the time, right?
So, basically, it would be not very reliable to test one function against the other
unless they differ in times by a very large margin, like few times slower or faster.
I am afraid my testing would produce no real results.
Maybe reduce the string count, so preempting tasks will have less chance to interrupt?
What about making the loop run with highest priority (SetThreadPriority API)?
Any ideas?
Post 14 Feb 2013, 15:54
View user's profile Send private message Send e-mail Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:29; edited 1 time in total
Post 14 Feb 2013, 17:40
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1419
Location: Toronto, Canada
AsmGuru62
I see the almost same results on this code: around 7000 to 9000 counts for 1000 strings.
Post 14 Feb 2013, 17:55
View user's profile Send private message Send e-mail Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1419
Location: Toronto, Canada
AsmGuru62
@edfed: your ATOI gives errors on negative values with 10 digits, like: "-1794094678"
Post 14 Feb 2013, 18:27
View user's profile Send private message Send e-mail Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1419
Location: Toronto, Canada
AsmGuru62
SetThreadPriority does not help.
Around same results for everyone's code. Weird...
Maybe I need to try more strings to convert? I have only a 1000 strings generated by VS 2008 C++ compiler.
Post 14 Feb 2013, 18:59
View user's profile Send private message Send e-mail Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:29; edited 1 time in total
Post 14 Feb 2013, 19:10
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
ok, i'll try to correct it Smile thx for the output
Post 14 Feb 2013, 21:32
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:28; edited 1 time in total
Post 15 Feb 2013, 19:32
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 9130
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
ok, we got the result & winner! for 2 million ascii string number!

i only see mine, HaHaAnonymous & johnfound code, i dont see AsmGuru62 code?

to check the winner, please view the spreadsheet Laughing

congratulation to winner! Cool thanks for participation!


Description: 10 runs result =) congratulation!
Download
Filename: result10runs.zip
Filesize: 10.21 KB
Downloaded: 120 Time(s)

Description: asm source how i did the benchmark, please create a file ascii.asm with 2,000,000 input string, use the vbs script file i attached.
Download
Filename: algobm.asm
Filesize: 9.13 KB
Downloaded: 154 Time(s)

Description: this vbs file will create 2,000,000 input string for your benchmark & testing purpose
Download
Filename: random-csv-file.zip
Filesize: 1.09 KB
Downloaded: 100 Time(s)

Post 16 Feb 2013, 12:55
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:27; edited 1 time in total
Post 16 Feb 2013, 13:34
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Thanks. This result only proves my belief that the smallest code is very often the fastest one.

BTW, what is the QueryPerformanceFrequency on the test machine?
Post 16 Feb 2013, 14:12
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:26; edited 1 time in total
Post 16 Feb 2013, 14:18
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 9130
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
@HaHaAnonymous
mine is slowest too, but there is room of improvement for everybody, which is good after all.

@JohnFound
there is truth in that statement. btw, congratulation! =)

Code:
        invoke  QueryPerformanceFrequency,_frequency
                        mov  eax, dword [_frequency]
                        mov  ecx, dword [_frequency + 4]
        cinvoke wsprintf,_obuffer,<'Performance Frequency : %lu %lu',13,10,0>,eax,ecx
        stdcall consoleWrite,_obuffer
    

Performance Frequency : 14318180 0
Post 16 Feb 2013, 20:23
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
i tested my version with 10 digits + minus sign, no problem, but in fact, i have a trim at the begining of the function and it gives that code:
maybe esi is not correctlly ajusted in the previous code posted cause trim does something with esi to point to the first non space char.
Code:
;return value from signed decimal at [esi] in eax
;when executing a command from command line,
;esi will point directlly after the command.
;carry set if valid decimal number
atoi:
.trim:
        call trim
        dec esi
.seekend:
        lodsb
        case al,' ',@f
        case al,'.',@f
        case al,',',@f
        case al,'!',@f
        casne al,0,.seekend
@@:
        dec esi
        push esi
        dec esi
        xor ebx,ebx
        mov edx,1
.next:
        movzx eax,byte[esi]
        dec esi
        case al,'-',.neg
        case al,' ',.end
        case al,',',.end
        case al,'.',.end
        casl al,'0',@f
        casg al,'9',@f
        sub al,'0'
        imul eax,edx
        add ebx,eax
        imul edx,10
        jmp .next
@@:
        pop esi
        clc
        mov eax,ebx
        ret
.neg:
        mov al,[esi]
        casne al,' ',@b
        neg ebx
.end:
        pop esi
        stc
        mov eax,ebx
        ret
                                   


Code:
trim:
;esi => text
;return esi => text - spaces
;al = [esi]
SPACE equ ' '
TAB equ 9
@@:
        lodsb
        case al,0,@f
        case al,SPACE,@b
        case al,TAB,@b
@@:
        ret

                                                  


i wonder if the function itself doesn't modify registers used in the test loop. and then lead to crash

i've tested it with itoa, just to verify the value entered is correctly converted in integer..

Code:
CR equ 13
LF equ 10
;transparent return
itoa:
        cmp eax,0
        mov byte[edi],' '
        jg @f
        mov byte[edi],'-'
        neg eax
@@:
        mov ecx,10
        mov ebx,edi
        push eax
@@:
        mov al,[ebx]
        inc ebx
        case al,CR,@f
        case al,LF,@f
        casne al,0,@b
@@:
        pop eax
        dec ebx
.loop:
        dec ebx
        casl ebx,edi,.end
        xor edx,edx
        div ecx
        casne edx,0,@f
        casne eax,0,@f
        mov dl,' '-'0'
@@:
        add dl,'0'
        cmp byte[ebx],'-'
        je .end
        mov [ebx],dl
        jmp .loop
.end:
        ret
                               
Post 16 Feb 2013, 20:53
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.