Segmentation fault...

13»

Comments

  • : : : Maximum thread limit...
    : : :
    : : : That's how strcmp worked. I had no idea.
    : : :
    : : : My way is compiled to just one instruction CMPS, wich is just 5 cycles on a Pentium.
    : : : The strcmp func could, as I can see it, only be optimised to a loop, (since there is two comparisons to be made).
    : : :
    : : : I don't know how to say this but something like this:
    : : : The case for it to match is small, one in 26 or similar.
    : : : Since strcmp is slower than my way, and the probability for a match is low, the extra comparison for a match will not differ much.
    : : :
    : : : My way: 25 times cmps and one strcmp
    : : : only strcmp: 26 times strcmp
    : :
    : : I agree with the fact that a call to strcmp() plus the extra comparison require a little more time to execute than your single comparison. However, unless you compare thousands of strings, do you think you'll notice the difference between the two methods?
    : :
    : : Steph
    : :
    : That's what I'm planning to do, compare thousands of strings.
    : I'm making a compiler.
    :
    On what platform is your compiler intended to run? If it is for Windows, I am not sure it is worth trying to avoid one comparison or a call to strcmp(). Windows does so many things behind your back that I do not think you'll save much time with a single byte comparison instead of two. For example: context switching (ie the process that allows Windows to switch from one task to another) requires to save many parameters (eg processor registers). To my mind, all this takes much more time than the single comparison you're trying to avoid.

    Steph
  • : : : Maximum thread limit...
    : : :
    : : : That's how strcmp worked. I had no idea.
    : : :
    : : : My way is compiled to just one instruction CMPS, wich is just 5 cycles on a Pentium.
    : : : The strcmp func could, as I can see it, only be optimised to a loop, (since there is two comparisons to be made).
    : : :
    : : : I don't know how to say this but something like this:
    : : : The case for it to match is small, one in 26 or similar.
    : : : Since strcmp is slower than my way, and the probability for a match is low, the extra comparison for a match will not differ much.
    : : :
    : : : My way: 25 times cmps and one strcmp
    : : : only strcmp: 26 times strcmp
    : :
    : : I agree with the fact that a call to strcmp() plus the extra comparison require a little more time to execute than your single comparison. However, unless you compare thousands of strings, do you think you'll notice the difference between the two methods?
    : :
    : : Steph
    : :
    : That's what I'm planning to do, compare thousands of strings.
    : I'm making a compiler.
    :
    I have performed some tests in order to show the differences between strcmp() and your method.
    The program is:
    [code]
    #include
    #include
    #include
    #include


    int main(int argc,char **argv)
    {
    char s[]="a";
    char t[sizeof s];
    DWORD ticks,ticks0;
    int i,max,temp;

    if (argc!=2) return 1;
    max=atoi(argv[1]);
    strcpy(t,"b");
    ticks0=GetTickCount();
    for (i=0;itest 1000000
    Time elapsed with strcmp() for 1000000 tests: 16 ms
    Time elapsed without strcmp() for 1000000 tests: 0 ms
    0

    Z:DataCTest>test 10000000
    Time elapsed with strcmp() for 10000000 tests: 78 ms
    Time elapsed without strcmp() for 10000000 tests: 16 ms
    0

    Z:DataCTest>test 1000000000
    Time elapsed with strcmp() for 1000000000 tests: 7078 ms
    Time elapsed without strcmp() for 1000000000 tests: 1454 ms
    0
    [/code]

    As you can see, even with one billion comparisons between the two strings, the difference is not so huge: 7s instead of 1.4s.

    Steph
  • : : : : Maximum thread limit...
    : : : :
    : : : : That's how strcmp worked. I had no idea.
    : : : :
    : : : : My way is compiled to just one instruction CMPS, wich is just 5 cycles on a Pentium.
    : : : : The strcmp func could, as I can see it, only be optimised to a loop, (since there is two comparisons to be made).
    : : : :
    : : : : I don't know how to say this but something like this:
    : : : : The case for it to match is small, one in 26 or similar.
    : : : : Since strcmp is slower than my way, and the probability for a match is low, the extra comparison for a match will not differ much.
    : : : :
    : : : : My way: 25 times cmps and one strcmp
    : : : : only strcmp: 26 times strcmp
    : : :
    : : : I agree with the fact that a call to strcmp() plus the extra comparison require a little more time to execute than your single comparison. However, unless you compare thousands of strings, do you think you'll notice the difference between the two methods?
    : : :
    : : : Steph
    : : :
    : : That's what I'm planning to do, compare thousands of strings.
    : : I'm making a compiler.
    : :
    : I have performed some tests in order to show the differences between strcmp() and your method.
    : The program is:
    : [code]
    : #include
    : #include
    : #include
    : #include
    :
    :
    : int main(int argc,char **argv)
    : {
    : char s[]="a";
    : char t[sizeof s];
    : DWORD ticks,ticks0;
    : int i,max,temp;
    :
    : if (argc!=2) return 1;
    : max=atoi(argv[1]);
    : strcpy(t,"b");
    : ticks0=GetTickCount();
    : for (i=0;itest 1000000
    : Time elapsed with strcmp() for 1000000 tests: 16 ms
    : Time elapsed without strcmp() for 1000000 tests: 0 ms
    : 0
    :
    : Z:DataCTest>test 10000000
    : Time elapsed with strcmp() for 10000000 tests: 78 ms
    : Time elapsed without strcmp() for 10000000 tests: 16 ms
    : 0
    :
    : Z:DataCTest>test 1000000000
    : Time elapsed with strcmp() for 1000000000 tests: 7078 ms
    : Time elapsed without strcmp() for 1000000000 tests: 1454 ms
    : 0
    : [/code]
    :
    : As you can see, even with one billion comparisons between the two strings, the difference is not so huge: 7s instead of 1.4s.
    :
    : Steph
    :
    5 times faster! Thats enough for me.
    Think if booting was five times faster.

    Thanks for the comparison.

    For the post:
    I'm using linux now, but this could easily be ported to windows, or anything I think. I hope my code is ansi, and if it is, it could in fact be ported to all computers.
  • : : : : : Maximum thread limit...
    : : : : :
    : : : : : That's how strcmp worked. I had no idea.
    : : : : :
    : : : : : My way is compiled to just one instruction CMPS, wich is just 5 cycles on a Pentium.
    : : : : : The strcmp func could, as I can see it, only be optimised to a loop, (since there is two comparisons to be made).
    : : : : :
    : : : : : I don't know how to say this but something like this:
    : : : : : The case for it to match is small, one in 26 or similar.
    : : : : : Since strcmp is slower than my way, and the probability for a match is low, the extra comparison for a match will not differ much.
    : : : : :
    : : : : : My way: 25 times cmps and one strcmp
    : : : : : only strcmp: 26 times strcmp
    : : : :
    : : : : I agree with the fact that a call to strcmp() plus the extra comparison require a little more time to execute than your single comparison. However, unless you compare thousands of strings, do you think you'll notice the difference between the two methods?
    : : : :
    : : : : Steph
    : : : :
    : : : That's what I'm planning to do, compare thousands of strings.
    : : : I'm making a compiler.
    : : :
    : : I have performed some tests in order to show the differences between strcmp() and your method.
    : : The program is:
    : : [code]
    : : #include
    : : #include
    : : #include
    : : #include
    : :
    : :
    : : int main(int argc,char **argv)
    : : {
    : : char s[]="a";
    : : char t[sizeof s];
    : : DWORD ticks,ticks0;
    : : int i,max,temp;
    : :
    : : if (argc!=2) return 1;
    : : max=atoi(argv[1]);
    : : strcpy(t,"b");
    : : ticks0=GetTickCount();
    : : for (i=0;itest 1000000
    : : Time elapsed with strcmp() for 1000000 tests: 16 ms
    : : Time elapsed without strcmp() for 1000000 tests: 0 ms
    : : 0
    : :
    : : Z:DataCTest>test 10000000
    : : Time elapsed with strcmp() for 10000000 tests: 78 ms
    : : Time elapsed without strcmp() for 10000000 tests: 16 ms
    : : 0
    : :
    : : Z:DataCTest>test 1000000000
    : : Time elapsed with strcmp() for 1000000000 tests: 7078 ms
    : : Time elapsed without strcmp() for 1000000000 tests: 1454 ms
    : : 0
    : : [/code]
    : :
    : : As you can see, even with one billion comparisons between the two strings, the difference is not so huge: 7s instead of 1.4s.
    : :
    : : Steph
    : :
    : 5 times faster! Thats enough for me.
    : Think if booting was five times faster.
    :
    : Thanks for the comparison.
    :
    : For the post:
    : I'm using linux now, but this could easily be ported to windows, or anything I think. I hope my code is ansi, and if it is, it could in fact be ported to all computers.
    :
    Yes, 5 times faster. But the difference become noticeable only for a huge number of comparisons (it's not so common to have a source file containing 1 billion characters), which all fail. In fact, the gain will be less than 5. Furthermore, source files contain many blanks with which you won't call strcmp(). That's why I think it will be rare for your compiler to make so many string comparisons.
    Are you writing a compiler in C? To compile C code? Anyway, I think there will be a part which depends on the OS. It cannot be 100% ANSI, can it?

    Steph
  • : : 5 times faster! Thats enough for me.
    : : Think if booting was five times faster.
    : :
    : : Thanks for the comparison.
    : :
    : : For the post:
    : : I'm using linux now, but this could easily be ported to windows, or anything I think. I hope my code is ansi, and if it is, it could in fact be ported to all computers.
    : :
    : Yes, 5 times faster. But the difference become noticeable only for a huge number of comparisons (it's not so common to have a source file containing 1 billion characters), which all fail. In fact, the gain will be less than 5. Furthermore, source files contain many blanks with which you won't call strcmp(). That's why I think it will be rare for your compiler to make so many string comparisons.
    : Are you writing a compiler in C? To compile C code? Anyway, I think there will be a part which depends on the OS. It cannot be 100% ANSI, can it?
    :
    : Steph
    :
    This is only in the lookup func, and if there is 1000 variables then it will need to search those at least 1000*1000 = 1000000 times, maybe more. I've taken care of the whitespace (and tokinisation).

    The compiler will be for a language of my own, opo. The design isn't finnished but I'm working on it.
    Why can't I write a compiler in ansi? printf() and getChar() are the io funcs I use (and the appropriate file versions).
  • : : : 5 times faster! Thats enough for me.
    : : : Think if booting was five times faster.
    : : :
    : : : Thanks for the comparison.
    : : :
    : : : For the post:
    : : : I'm using linux now, but this could easily be ported to windows, or anything I think. I hope my code is ansi, and if it is, it could in fact be ported to all computers.
    : : :
    : : Yes, 5 times faster. But the difference become noticeable only for a huge number of comparisons (it's not so common to have a source file containing 1 billion characters), which all fail. In fact, the gain will be less than 5. Furthermore, source files contain many blanks with which you won't call strcmp(). That's why I think it will be rare for your compiler to make so many string comparisons.
    : : Are you writing a compiler in C? To compile C code? Anyway, I think there will be a part which depends on the OS. It cannot be 100% ANSI, can it?
    : :
    : : Steph
    : :
    : This is only in the lookup func, and if there is 1000 variables then it will need to search those at least 1000*1000 = 1000000 times, maybe more. I've taken care of the whitespace (and tokinisation).
    :
    : The compiler will be for a language of my own, opo. The design isn't finnished but I'm working on it.
    : Why can't I write a compiler in ansi? printf() and getChar() are the io funcs I use (and the appropriate file versions).
    :
    What ANSI functions allow to create an EXE file? I really cannot see how you can create the EXE file that your compiler has to produce, using ANSI C.

    Steph
  • : : : : 5 times faster! Thats enough for me.
    : : : : Think if booting was five times faster.
    : : : :
    : : : : Thanks for the comparison.
    : : : :
    : : : : For the post:
    : : : : I'm using linux now, but this could easily be ported to windows, or anything I think. I hope my code is ansi, and if it is, it could in fact be ported to all computers.
    : : : :
    : : : Yes, 5 times faster. But the difference become noticeable only for a huge number of comparisons (it's not so common to have a source file containing 1 billion characters), which all fail. In fact, the gain will be less than 5. Furthermore, source files contain many blanks with which you won't call strcmp(). That's why I think it will be rare for your compiler to make so many string comparisons.
    : : : Are you writing a compiler in C? To compile C code? Anyway, I think there will be a part which depends on the OS. It cannot be 100% ANSI, can it?
    : : :
    : : : Steph
    : : :
    : : This is only in the lookup func, and if there is 1000 variables then it will need to search those at least 1000*1000 = 1000000 times, maybe more. I've taken care of the whitespace (and tokinisation).
    : :
    : : The compiler will be for a language of my own, opo. The design isn't finnished but I'm working on it.
    : : Why can't I write a compiler in ansi? printf() and getChar() are the io funcs I use (and the appropriate file versions).
    : :
    : What ANSI functions allow to create an EXE file? I really cannot see how you can create the EXE file that your compiler has to produce, using ANSI C.
    :
    : Steph
    :
    I'm producing the assembly output (wich all compilers do), that is then going to be assembled and linked to an exe, (or in my case, an elf file).

    What would be hard to make an exe?
    [code]
    FILE* f = fopen("test.exe","o");
    //output some binary data
    fclose(f);
    [/code]
    This is written for head, so it may not be correct.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories