Thread: Testpad for itoa()

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Thanks cyberfish, would you transfer all those nice points
    in something C-like? I'd appreciate it very much.
    If you have a better testpad than mine, and it would not
    be so strange, after all you have far more experience than me
    with C-stuff, please show it.
    By the way, the function you proposed is a good one,
    did you debug it for numbers smaller than 1,000?
    Well I don't really have time right now, but which one do you need help with?

    The first one would be something like
    Code:
    generate an array of 1000000 random integers
    make an array of 1000000 buffers to hold the answers
    start timing
    call the function to add commas (and store answers in the second array)
    stop timing
    for every number, use a known correct algorithm to calculate the string, and compare it to the second array
    And no, I didn't try with <1000. Will do that tonight.

  2. #2
    Registered User
    Join Date
    Jun 2010
    Posts
    182
    Quote Originally Posted by cyberfish View Post
    Well I don't really have time right now, but
    which one do you need help with?

    The first one would be something like
    Code:
    - generate an array of 1000000 random integers
    - make an array of 1000000 buffers to hold the answers
    - start timing
    - call the function to add commas (and store answers
      in the second array)
    - stop timing
    - for every number, use a known correct algorithm to 
      calculate the string, and compare it to the second array
    And no, I didn't try with <1000. Will do that tonight.
    That is fairly good to do after I have a bounch of working
    functions to test and it'll take quite a while to code for a
    beginner like me.
    I already made a pre-test with my testpad and most of the
    functions tested need to be fixed.
    So far I'm still waiting for the working versions of:
    - quzah
    - cyberfish
    - Elysia
    - whiteflags - not sure
    - Adak ?
    - maybe somebody else

    All of us haven't plenty of time to dedicate to it, so we have to go self
    paced. Actually I'm not in a hurry. As time permits and
    I study more C-stuff, things are going to speed up a little. And
    somebody has already some testpad to test his functions as well.

    A last thing: what about itoas() --> from integer to ASCII with
    s-eparator ? I hope it's not around yet. :-)

    Let's see what happens and enjoy your week-end.
    Last edited by frktons; 07-09-2010 at 01:14 PM.

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by frktons View Post
    So far I'm still waiting for the working versions of:
    - whiteflags - not sure
    I have shown you a similar unit test (the main function) to your test pad. If you can't get it to work with your code, I can't help you unless you're specific. But with the version I posted here, all you need to do is invoke foo. O_o

  4. #4
    Registered User
    Join Date
    Jun 2010
    Posts
    182
    Quote Originally Posted by whiteflags View Post
    I have shown you a similar unit test (the main function) to your test pad. If you can't get it to work with your code, I can't help you unless you're specific. But with the version I posted here, all you need to do is invoke foo. O_o
    Thanks for your explanation, I'll try again, maybe I get it working
    on my testpad.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
                        Testing version : Elysia
                     ------------------------------
     Testing on AMD Athlon II X2 250 (3 GHz)
     OS = Windows 7 Ultimate 64 bit  --  Compiler = Microsoft Visual Studio 2010
    
     The value of num is: -1234567890
    
     The formatted value of num is: -1,234,567,890
    
     Elapsed time: 208 ms to perform 10,000,000 cycles
     -------------------------------------------------------
    
     handling 0 ---> 0
     handling 12 ---> 12
     handling 256 ---> 256
     handling 1000 --> 1,000
     handling 1000000 ---> 1,000,000
     handling 1000000000 ---> 1,000,000,000
     handling 2147483647 -> 2,147,483,647
     handling -2147483648 -> -2,147,483,648
    Press any key to continue . . .
    Code:
    // ----------------------------------------------------------------------------------------------
    // Prog_name: testpad.c 
    // A program for testing functions formatting integer numbers with 
    // thousand separators and sign. 
    //-----------------------------------------------------------------------------------------------
    // Created with Pelles C for Windows 6.00.4
    // Standard ISO C99
    //-----------------------------------------------------------------------------------------------
    // Date: 09 july 2010
    // Testpad by frktons
    //-----------------------------------------------------------------------------------------------
    
    #include <stdio.h>
    #include <time.h>
    #include <string.h>
    
    //-----------------------------------------------------------------------------------------------
    // Function prototype for itoa(). Takes in the number to 
    // format, and the pointer of the buffer to fill. Returns an int.
    //-----------------------------------------------------------------------------------------------
    
    void itoa(long num, char []);
    
    char digits_table[999999][8];
    
    //-----------------------------------------------------------------------------------------------
    
    int main(void)
    {
     
    	for (int i = 0; i < 999999; i++)
    	{
    		for (int j = 0; j < 8; j++)
    		{
    			digits_table[i][0] = ',';
    			digits_table[i][1] = '0' + char(i / 100000);
    			digits_table[i][2] = '0' + char(i / 10000 % 10);
    			digits_table[i][3] = '0' + char(i / 1000 % 10);
    			digits_table[i][4] = ',';
    			digits_table[i][5] = '0' + char(i / 100 % 10);
    			digits_table[i][6] = '0' + char(i / 10 % 10);
    			digits_table[i][7] = '0' + char(i % 10);
    		}
    	}
    	
    	long num = -1234567890;          // test number
        int cycles = 0;
    
    
    
        clock_t start = 0;              // initial time
        clock_t stop = 0;              // end time 
        const char *ver = "Elysia";         // Program version
        char buffer[50] = {'\0'};        // string array for the formatted number
                                                  // 10 digits max + 3 separators max + sign + NULL
     
        long times = 10000000;      // for testing performance set this number for repetitions
    
    //-----------------------------------------------------------------------------------------------
    // HW-SW platform 
    //-----------------------------------------------------------------------------------------------
        const char *OS = "Windows 7 Ultimate 64 bit";
    	const char *CPU = "AMD Athlon II X2 250 (3 GHz)";
        const char *compiler = "Microsoft Visual Studio 2010";
    //-----------------------------------------------------------------------------------------------
    
        printf("\n\t\t    Testing version : %s \n",ver);
        printf("\t\t ------------------------------\n");
    
        printf(" Testing on %s\n",CPU);
        printf(" OS = %s  --  Compiler = %s\n",OS,compiler);
        printf("\n The value of num is: %d\n",num);
    
        start = clock();
    
        for (cycles = 0; cycles < times; cycles++) {
    
            itoa(num,buffer);
    
        } // end for
    
        stop = clock();
        
        printf("\n The formatted value of num is: %s\n",buffer);
    
        itoa((long)(stop-start)/(CLOCKS_PER_SEC/1000),buffer);
        printf("\n Elapsed time: %s ms",buffer);
    
        itoa(times,buffer);
        printf(" to perform %s cycles\n",buffer);
    
    
    //------------------------------------------------------------------------------
    // Test some numbers
    //------------------------------------------------------------------------------
    
        printf(" -------------------------------------------------------\n");
    
        long test = -2147483647 - 1;
    	itoa(0,buffer);
        printf("\n handling 0 ---> %s",buffer);
        itoa(12,buffer);
        printf("\n handling 12 ---> %s",buffer);
        itoa(256,buffer);
        printf("\n handling 256 ---> %s",buffer);
        itoa(1000,buffer);
        printf("\n handling 1000 --> %s",buffer);
        itoa(1000000,buffer);
        printf("\n handling 1000000 ---> %s",buffer);
        itoa(1000000000,buffer);
        printf("\n handling 1000000000 ---> %s",buffer);
        itoa(2147483647,buffer);
        printf("\n handling 2147483647 -> %s",buffer);
        itoa(test,buffer);
        printf("\n handling -2147483648 -> %s\n",buffer);
    
        return 0;
    }
    
    //---------------------------------------------------------------
    // itoa() - Elysia's version
    //---------------------------------------------------------------
    __forceinline void itoa(long num, char buffer[])
    {
    	int remain = 0;                  // integer variable to store the remainder
    	bool neg = false;
    	const int sizeof_buffer = 30;
    	unsigned long newnum;
    
    	memset(buffer, 0, 50);
    
    	if (num == 0)
    	{
    		strcpy(buffer, "0");
    		return;
    	}
    	if (num < 0)
    	{
    		neg = true;
    		buffer[0] = '-';
    		newnum = -num; // transform number to positive if negative
    	}
    	else
    		newnum = num;
    
    	int x, copy_from_offset = 0;
    	for (x = sizeof_buffer - 1; newnum; x -= 8)
    	{
    		if (newnum < 100000)
    		{
    			copy_from_offset = 1;
    			if (newnum < 10) copy_from_offset = 6;
    			else if (newnum < 100) copy_from_offset = 5;
    			else if (newnum < 1000) copy_from_offset = 4;
    			else if (newnum < 10000) copy_from_offset = 2;
    		}
    		remain = newnum % 1000000;
    		newnum /= 1000000;
    		memcpy(&buffer[x - 8], digits_table[remain], 8);
    	} 
    
    	int copy_to = 0;
    	if (neg) copy_to++;
    	memmove(&buffer[copy_to], &buffer[x + 1] + copy_from_offset, sizeof_buffer - x - 1 - copy_from_offset);
    	buffer[sizeof_buffer - x - 1] = '\0';
    }
    There you go. Quick and dirt. x64 version (beats x86 version by ~2x).
    Last edited by Elysia; 07-09-2010 at 12:20 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Jun 2010
    Posts
    182
    Quote Originally Posted by Elysia View Post
    Code:
                        Testing version : Elysia
                     ------------------------------
     Testing on AMD Athlon II X2 250 (3 GHz)
     OS = Windows 7 Ultimate 64 bit  --  Compiler = Microsoft Visual Studio 2010
    
     The value of num is: -1234567890
    
     The formatted value of num is: -1,234,567,890
    
     Elapsed time: 208 ms to perform 10,000,000 cycles
     -------------------------------------------------------
    
     handling 0 ---> 0
     handling 12 ---> 12
     handling 256 ---> 256
     handling 1000 --> 1,000
     handling 1000000 ---> 1,000,000
     handling 1000000000 ---> 1,000,000,000
     handling 2147483647 -> 2,147,483,647
     handling -2147483648 -> -2,147,483,648
    Press any key to continue . . .
    Code:
    // ----------------------------------------------------------------------------------------------
    // Prog_name: testpad.c 
    // A program for testing functions formatting integer numbers with 
    // thousand separators and sign. 
    //-----------------------------------------------------------------------------------------------
    // Created with Pelles C for Windows 6.00.4
    // Standard ISO C99
    //-----------------------------------------------------------------------------------------------
    // Date: 09 july 2010
    // Testpad by frktons
    //-----------------------------------------------------------------------------------------------
    
    #include <stdio.h>
    #include <time.h>
    #include <string.h>
    
    //-----------------------------------------------------------------------------------------------
    // Function prototype for itoa(). Takes in the number to 
    // format, and the pointer of the buffer to fill. Returns an int.
    //-----------------------------------------------------------------------------------------------
    
    void itoa(long num, char []);
    
    char digits_table[999999][8];
    
    //-----------------------------------------------------------------------------------------------
    
    int main(void)
    {
     
    	for (int i = 0; i < 999999; i++)
    	{
    		for (int j = 0; j < 8; j++)
    		{
    			digits_table[i][0] = ',';
    			digits_table[i][1] = '0' + char(i / 100000);
    			digits_table[i][2] = '0' + char(i / 10000 % 10);
    			digits_table[i][3] = '0' + char(i / 1000 % 10);
    			digits_table[i][4] = ',';
    			digits_table[i][5] = '0' + char(i / 100 % 10);
    			digits_table[i][6] = '0' + char(i / 10 % 10);
    			digits_table[i][7] = '0' + char(i % 10);
    		}
    	}
    	
    	long num = -1234567890;          // test number
        int cycles = 0;
    
    
    
        clock_t start = 0;              // initial time
        clock_t stop = 0;              // end time 
        const char *ver = "Elysia";         // Program version
        char buffer[50] = {'\0'};        // string array for the formatted number
                                                  // 10 digits max + 3 separators max + sign + NULL
     
        long times = 10000000;      // for testing performance set this number for repetitions
    
    //-----------------------------------------------------------------------------------------------
    // HW-SW platform 
    //-----------------------------------------------------------------------------------------------
        const char *OS = "Windows 7 Ultimate 64 bit";
    	const char *CPU = "AMD Athlon II X2 250 (3 GHz)";
        const char *compiler = "Microsoft Visual Studio 2010";
    //-----------------------------------------------------------------------------------------------
    
        printf("\n\t\t    Testing version : %s \n",ver);
        printf("\t\t ------------------------------\n");
    
        printf(" Testing on %s\n",CPU);
        printf(" OS = %s  --  Compiler = %s\n",OS,compiler);
        printf("\n The value of num is: %d\n",num);
    
        start = clock();
    
        for (cycles = 0; cycles < times; cycles++) {
    
            itoa(num,buffer);
    
        } // end for
    
        stop = clock();
        
        printf("\n The formatted value of num is: %s\n",buffer);
    
        itoa((long)(stop-start)/(CLOCKS_PER_SEC/1000),buffer);
        printf("\n Elapsed time: %s ms",buffer);
    
        itoa(times,buffer);
        printf(" to perform %s cycles\n",buffer);
    
    
    //------------------------------------------------------------------------------
    // Test some numbers
    //------------------------------------------------------------------------------
    
        printf(" -------------------------------------------------------\n");
    
        long test = -2147483647 - 1;
    	itoa(0,buffer);
        printf("\n handling 0 ---> %s",buffer);
        itoa(12,buffer);
        printf("\n handling 12 ---> %s",buffer);
        itoa(256,buffer);
        printf("\n handling 256 ---> %s",buffer);
        itoa(1000,buffer);
        printf("\n handling 1000 --> %s",buffer);
        itoa(1000000,buffer);
        printf("\n handling 1000000 ---> %s",buffer);
        itoa(1000000000,buffer);
        printf("\n handling 1000000000 ---> %s",buffer);
        itoa(2147483647,buffer);
        printf("\n handling 2147483647 -> %s",buffer);
        itoa(test,buffer);
        printf("\n handling -2147483648 -> %s\n",buffer);
    
        return 0;
    }
    
    //---------------------------------------------------------------
    // itoa() - Elysia's version
    //---------------------------------------------------------------
    __forceinline void itoa(long num, char buffer[])
    {
    	int remain = 0;                  // integer variable to store the remainder
    	bool neg = false;
    	const int sizeof_buffer = 30;
    	unsigned long newnum;
    
    	memset(buffer, 0, 50);
    
    	if (num == 0)
    	{
    		strcpy(buffer, "0");
    		return;
    	}
    	if (num < 0)
    	{
    		neg = true;
    		buffer[0] = '-';
    		newnum = -num; // transform number to positive if negative
    	}
    	else
    		newnum = num;
    
    	int x, copy_from_offset = 0;
    	for (x = sizeof_buffer - 1; newnum; x -= 8)
    	{
    		if (newnum < 100000)
    		{
    			copy_from_offset = 1;
    			if (newnum < 10) copy_from_offset = 6;
    			else if (newnum < 100) copy_from_offset = 5;
    			else if (newnum < 1000) copy_from_offset = 4;
    			else if (newnum < 10000) copy_from_offset = 2;
    		}
    		remain = newnum % 1000000;
    		newnum /= 1000000;
    		memcpy(&buffer[x - 8], digits_table[remain], 8);
    	} 
    
    	int copy_to = 0;
    	if (neg) copy_to++;
    	memmove(&buffer[copy_to], &buffer[x + 1] + copy_from_offset, sizeof_buffer - x - 1 - copy_from_offset);
    	buffer[sizeof_buffer - x - 1] = '\0';
    }
    There you go. Quick and dirt. x64 version (beats x86 version by ~2x).
    Very good Elysia, thanks for your collaboration.
    Unfortunately it seems not strictly C99 standard:
    Code:
    Building testpad.obj.
    testpad.c(36): error #2039: Illegal expression.
    testpad.c(36): error #2068: Expected a function but found 'int'.
    testpad.c(36): error #2168: Operands of '+' have incompatible types 'int' and 'void'.
    testpad.c(37): error #2039: Illegal expression.
    testpad.c(37): error #2068: Expected a function but found 'int'.
    testpad.c(37): error #2168: Operands of '+' have incompatible types 'int' and 'void'.
    testpad.c(38): error #2039: Illegal expression.
    testpad.c(38): error #2068: Expected a function but found 'int'.
    testpad.c(38): error #2168: Operands of '+' have incompatible types 'int' and 'void'.
    testpad.c(40): error #2039: Illegal expression.
    testpad.c(40): error #2068: Expected a function but found 'int'.
    testpad.c(40): error #2168: Operands of '+' have incompatible types 'int' and 'void'.
    testpad.c(41): error #2039: Illegal expression.
    testpad.c(41): error #2068: Expected a function but found 'int'.
    testpad.c(41): error #2168: Operands of '+' have incompatible types 'int' and 'void'.
    testpad.c(42): error #2039: Illegal expression.
    testpad.c(42): error #2068: Expected a function but found 'int'.
    testpad.c(42): error #2168: Operands of '+' have incompatible types 'int' and 'void'.
    testpad.c(126): error #2048: Undeclared identifier 'bool'.
    testpad.c(126): error #2001: Syntax error: expected ';' but found 'neg'.
    testpad.c(126): error #2048: Undeclared identifier 'neg'.
    testpad.c(126): error #2048: Undeclared identifier 'false'.
    testpad.c(139): error #2048: Undeclared identifier 'true'.
    testpad.c(126): warning #2114: Local 'bool' is not referenced.
    *** Error code: 1 ***
    Done.
    My compiler complains about:

    Code:
    			digits_table[i][0] = ',';
    			digits_table[i][1] = '0' + char(i / 100000);
    			digits_table[i][2] = '0' + char(i / 10000 % 10);
    			digits_table[i][3] = '0' + char(i / 1000 % 10);
    			digits_table[i][4] = ',';
    			digits_table[i][5] = '0' + char(i / 100 % 10);
    			digits_table[i][6] = '0' + char(i / 10 % 10);
    			digits_table[i][7] = '0' + char(i % 10);
    Any possible standard coding?

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Those look like function-style casts from C++. I expect that they should be:
    Code:
    digits_table[i][1] = '0' + (char)(i / 100000);
    etc. However, the explicit cast is probably unnecessary anyway, since the result would be promoted back to int for the addition.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Right. You complained about that before, but you never said if my solution fixed it... I don't think GCC likes that syntax for some reason.
    Change it to:
    Code:
    			digits_table[i][0] = ',';
    			digits_table[i][1] = '0' + (char)(i / 100000);
    			digits_table[i][2] = '0' + (char)(i / 10000 % 10);
    			digits_table[i][3] = '0' + (char)(i / 1000 % 10);
    			digits_table[i][4] = ',';
    			digits_table[i][5] = '0' + (char)(i / 100 % 10);
    			digits_table[i][6] = '0' + (char)(i / 10 % 10);
    			digits_table[i][7] = '0' + (char)(i % 10);
    And try again.

    Also, for bool, try:
    Code:
    #ifndef _MSC_VER
    #include <stdbool.h>
    #endif
    MSVC doesn't support C99.
    The first line should be cast to char since otherwise you'll get a warning of int to char: possible loss of data. You could add % 10 to it, or you could cast it. Your choice. The rest doesn't seem to need the cast, though.

    And did you have to quote the entire post?
    Last edited by Elysia; 07-09-2010 at 01:31 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Jun 2010
    Posts
    182
    OK Elysia, changing the code with (char) typecasting worked.
    The results on my pc:
    Code:
                        Testing version : Elysia
                     ------------------------------
     Testing on Intel Core Duo 6600 2.4 Ghz
     OS = Windows 7 Ultimate 64 bit  --  Compiler = Pelles C 6.00.4
    
     The value of num is: -1234567890
    
     The formatted value of num is: -1,234,567,890
    
     Elapsed time: 936 ms to perform 10,000,000 cycles
     -------------------------------------------------------
    
     handling 0 ---> 0
     handling 12 ---> 12
     handling 256 ---> 256
     handling 1000 --> 1,000
     handling 1000000 ---> 1,000,000
     handling 1000000000 ---> 1,000,000,000
     handling 2147483647 -> 2,147,483,647
     handling -2147483648 -> -2,147,483,648
    Press any key to continue...
    This is going to be one of the selected working solutions.

    If you post the EXE compiled with 64 bit features, it'll probably
    test faster on my pc as well.

    Thanks
    Last edited by frktons; 07-09-2010 at 02:04 PM.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Compile an x64 build, as well, should you be able. The code was made to lend itself well to that since it performs a 64-bit move per loop.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Jun 2010
    Posts
    182
    Quote Originally Posted by Elysia View Post
    Compile an x64 build, as well, should you be able. The code was made to lend itself well to that since it performs a 64-bit move per loop.
    I don't think I can do it with Pelles' C. If I use the command line CL.EXE
    from MSVC 2010, that I have somewhere on my pc, what command line should I use?

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No idea. Not using command lines (what do you think IDEs are for?).
    But this is all the more reason to drop your compiler. We've already shown that GCC and MSVC beats it at optimizing.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by frktons
    I don't think I can do it with Pelles' C.
    The Pelles C homepage states that it supports 64-bit compilation, though obtaining the documentation on how to do that is another matter as there are no obvious links on the website or wiki.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I suppose you should also rerun iMalc's code to measure it in ms instead of clock ticks.
    (For a fair comparison; otherwise we don't know by how many orders of magnitude slower or faster other codes are.)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Registered User
    Join Date
    Jun 2010
    Posts
    182
    Quote Originally Posted by Elysia View Post
    I suppose you should also rerun iMalc's code
    to measure it in ms instead of clock ticks.
    (For a fair comparison; otherwise we don't know by how many orders
    of magnitude slower or faster other codes are.)
    My pc is 32 bit, so Pelles'C 64 bit refuses to compile in x64 mode.

    Code:
        itoa((long)(stop-start)/(CLOCKS_PER_SEC/1000),buffer);
        printf("\n Elapsed time: %s ms",buffer);
    I didn't see you changed the timing system, ok, I'll change it on the
    testpad and retest iMalc version.
    Results following:

    Code:
                        Testing version : iMalc
                     ------------------------------
     Testing on Intel Core Duo 6600 2.4 Ghz
     OS = Windows 7 Ultimate 64 bit  --  Compiler = Pelles C 6.00.4
    
     The value of num is: -1234567890
    
     The formatted value of num is: -1,234,567,890
    
     Elapsed time: 297 ms to perform 10,000,000 cycles
     -------------------------------------------------------
    
     handling 0 ---> 0
     handling 12 ---> 12
     handling 256 ---> 256
     handling 1000 --> 1,000
     handling 1000000 ---> 1,000,000
     handling 1000000000 ---> 1,000,000,000
     handling 2147483647 -> 2,147,483,647
     handling -2147483648 -> -2,147,483,648
    See you later :-)

    Edit: Well, doesn't seem to change a lot from previous system.
    Last edited by frktons; 07-09-2010 at 02:33 PM.

Popular pages Recent additions subscribe to a feed