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.

Objectives

The basic objectives of the Peregrine language are as follows:

THE BELAMY

Sign up for your weekly dose of what's up in emerging technology.
  • 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.

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.

More Great AIM Stories

Dr. Nivash Jeevanandam
Nivash holds a doctorate in information technology and has been a research associate at a university and a development engineer in the IT industry. Data science and machine learning excite him.

Our Upcoming Events

Conference, in-person (Bangalore)
Machine Learning Developers Summit (MLDS) 2023
19-20th Jan, 2023

Conference, in-person (Bangalore)
Rising 2023 | Women in Tech Conference
16-17th Mar, 2023

Conference, in-person (Bangalore)
Data Engineering Summit (DES) 2023
27-28th Apr, 2023

Conference, in-person (Bangalore)
MachineCon 2023
23rd Jun, 2023

Conference, in-person (Bangalore)
Cypher 2023
20-22nd Sep, 2023

3 Ways to Join our Community

Whatsapp group

Discover special offers, top stories, upcoming events, and more.

Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

Subscribe to our newsletter

Get the latest updates from AIM