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 http://cobra-language.com/docs/python/ "...Speed")


Yes, it can be faster!

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

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

Execution times on a slow computer (1 GHz cpu):
Python
- gib_detect_train.py : 19 seconds
Cobra
- 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
    https://github.com/rrenaud/Gibberish-Detector
  • copy into a working directory these files:
    big.txt, good.txt, bad.txt # these are the input files of "gib_detect_train.py"
    Gib1.cobra
    Gib2.cobra
  • compile in the same directory:
    cobra -c Gib1
    cobra -c Gib2
  • execute in the same directory:
    Gib1
    Gib2
  • compare with
    gib_detect_train.py # or with
    _gib_detect_train.py # (the same code, but with timing and print...)

Gib1.cobra
(3.67 KiB) Downloaded 338 times

Gib2.cobra
version 2.1
(6.32 KiB) Downloaded 289 times

_gib_detect_train.py
(1.88 KiB) Downloaded 328 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.