Forums

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 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 1513 times

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

_gib_detect_train.py
(1.88 KiB) Downloaded 1692 times
Last edited by thriwkin on Fri Jul 04, 2014 3:10 am, edited 1 time in total.
thriwkin
 
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.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 88 guests

cron