A sample program: Gibberish Detector

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

A sample program: Gibberish Detector

Postby thriwkin » Fri Jun 27, 2014 9:49 am

Cobra's performance is close or equal to that of C# and Java,
and is therefore significantly faster than Python.

(from "...Speed")

Yes, it can be faster!

For example, the Python program Gibberish Detector has a very time-consuming part:
the function train in

I ported this program to Cobra and wrote two versions: Gib1 and Gib2.

Execution times on a slow computer (1 GHz cpu):
- : 19 seconds
- Gib1 : 2 times faster (8 seconds)
- Gib2 : 90 times faster (0.21 seconds)

90 times faster, that's quite impressive!

(Edited: I simplified Gib2, and replaced the uploaded file. )

How to build and compare the programs:
  • download the Python program from
  • copy into a working directory these files:
    big.txt, good.txt, bad.txt # these are the input files of ""
  • compile in the same directory:
    cobra -c Gib1
    cobra -c Gib2
  • execute in the same directory:
  • compare with # or with # (the same code, but with timing and print...)

(3.67 KiB) Downloaded 434 times

version 2.1
(6.32 KiB) Downloaded 383 times
(1.88 KiB) Downloaded 440 times
Last edited by thriwkin on Fri Jul 04, 2014 3:10 am, edited 1 time in total.
Posts: 26

Re: A sample program: Gibberish Detector

Postby Charles » Thu Jul 03, 2014 10:14 pm

Thanks for sharing this. Of course the nice thing is that Cobra is not only faster (which is also true of say C++), but like Python, stays true to enabling clean, cruftless code.
Posts: 2514
Location: Los Angeles, CA

Return to Discussion

Who is online

Users browsing this forum: No registered users and 11 guests