Page 1 of 1

A sample program: Gibberish Detector

PostPosted: Fri Jun 27, 2014 9:49 am
by thriwkin
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 381 times

version 2.1
(6.32 KiB) Downloaded 331 times
(1.88 KiB) Downloaded 369 times

Re: A sample program: Gibberish Detector

PostPosted: Thu Jul 03, 2014 10:14 pm
by Charles
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.