Now Reading
Everything You Need To Know About Peregrine, A New Programming Language

Everything You Need To Know About Peregrine, A New Programming Language

  • Peregrine is a Python-like programming language that is as fast as C.

Peregrine is a new programming language with a syntax similar to Python but execution speed comparable to C (currently under development). Recently, Ethan, one of the eight developers, shared some recent updates to Peregrine. 

While describing the Peregrine programming language, Ethan stated, “If you’re familiar with Python, you’re probably aware that it’s both simple to use and slow – which is a little inconvenient. To address this, my friends and I are developing a new programming language called Peregrine, which has a very similar syntax. Peregrine is compiled to C, allowing it to operate at the same speed as C.” Moreover, it was created by the developers as a quick alternative to Python and a simple alternative to C.

Apply>>

Objectives

The basic objectives of the Peregrine language are as follows:

  • Simple to use 
  • Quick
  • Highly modular 
  • Takes up less memory
  • Faster compilation

These are a few of Peregrine’s most recent enhancements:

Type Inference

Peregrine’s Type Inference function is one of the company’s newest additions, making it possible to write Peregrine code straightforwardly. Type inference is the process of determining the type of an expression in a formal language automatically. This category includes programming languages and mathematical type systems, as well as natural languages in certain disciplines of computer science and linguistics.

if/else/match

Despite the fact that this appears to be a typical feature in any programming language, it takes time to implement these. There isn’t much to say about it because it appears in every programming language.

Ccode

Peregrine now has a new feature called Ccode, which is now ready for use. Peregrine supports the execution of C code through the use of Ccode. Here’s an illustration:

Source: Peregrine programming

The variables specified outside the Ccode block can be utilised inside the Ccode block, and vice versa, as seen in the example above. This also implies that any C library can be imported and used in Peregrine through the use of Ccode.

Inline Assembly

Peregrine incorporates inline assembly. In programming, some compilers include an inline assembler as a feature that enables the inclusion of low-level assembly code within a programme alongside code built from a higher-level language such as C or Ada.

Here is an illustration:

Source: Peregrine programming

As expected, this program prints 95. In a similar vein, there are several other examples in the Peregrine test directory

Benchmark

The author asserts that Peregrine is as fast as C, providing several benchmarks to support this assertion.

Source: Peregrine programming

According to the author, here, the Fibonacci series from 0 to 40 was calculated recursively using Python on the left side, which took 32 seconds. On the other hand, Peregrine on the right side took only 1 second, making it 32 times faster. Furthermore, it is evident that its syntax is extremely similar to that of the Python programming language. As a point of reference, here is a benchmark with C.

See Also

Source: Peregrine programming

According to the above result, Peregrine is as quick (if not faster) than C (both took 1 sec)

Why is C so fast?

Modern programming languages include garbage collection, dynamic typing, and other features that make designing programmes easier. The catch is that this adds additional processing overhead, which degrades the application’s performance. C lacks all of that, which means there is no overhead, but the programmer must be able to allocate and free memory to avoid memory leaks and cope with static types of variables. Hence C is faster than other modern languages.

Comments

In response to a comment in DEV Community, “Python could improve the example of Fibonacci by resolving the performance issue with @lru cache for the memorising, which would improve the performance of the code. In this case, it is a problem of memory consumption. It would be fantastic to demonstrate the performance and memory consumption comparison between Python and Peregrine for this example to demonstrate how effective the Peregrine language is in this situation. Otherwise, I have my doubts that Peregrine is consuming more memory.” 

Source: Peregrine programming

Saptak Bhowmik, a contributor of the Peregrine language, responded as follows: “Using @lru cache, on the other hand, is a form of cheating. Compared with a multithreaded Python application against a single-threaded C programme, Python is quite likely to win”.

Planned Features 

The following are the features that will be included in the upcoming release.

  • Structs 
  • Additional decorators for a variety of purposes
  • Peregrine’s Python ecosystem – Peregrine supports the Python module.

Peregrine is scheduled to release version 0.0.1 in March this year, according to the contributors.
For more information: Repo: Github.

What Do You Think?

Subscribe to our Newsletter

Get the latest updates and relevant offers by sharing your email.
Join our Telegram Group. Be part of an engaging community

Copyright Analytics India Magazine Pvt Ltd

Scroll To Top