Don't post a stupid YT video..

26 views
Skip to first unread message

The Beez

unread,
Jan 19, 2024, 10:54:24 AMJan 19
to 4tH-compiler
.. unless you REALLY know what you're doing. Watch this one: https://www.youtube.com/watch?v=MHBG_R_dhwk

Now not that this guy uses the getline() function without knowing what's under the hood. And there are quite a few things going on - like strchr(), realloc(), strlen(), strcpy(), fgets().

Even fgets() gets its hands dirty, while at least some implementations are doing their work straight in the filebuffer. 

So I decided to make a quick alternative, based on the Accept() function in exec_4th():

int rawline (char* line, int size, FILE* f)
{
  int ch;
  int count = 0;
  size--;
 
  while (((ch = fgetc (f)) != EOF) && (count < size))
  {
    if (ch == (int) '\n') break;
    line [count++] = (char) ch;
  }

  line [count] = '\0';
  return (ch);
}


Agreed, it's not my finest work - but it obliterated his claim:

C: 0,037s
Python: 0,144s

The worst part came when I thought "let's throw in 4tH". I mean after all, it's just a matter of:

0 begin refill while 1+ repeat . cr

Oops..

C: 0,037s
Python: 0,144s
4tH: 0,049s

Barely slower than C. Much faster than Python! 

Hans Bezemer




Reply all
Reply to author
Forward
0 new messages