Just For Fun: ARE (AngleScript Runtime Enviroment) and other stuff...

Started by
0 comments, last by WitchLord 14 years, 10 months ago
So I'm nearly done with the project I have integrated AngelScript into, and I'll post that here for you guys to check out when it's ready. But all this working with AS got me to thinking that'd it'd be cool to be able to use AngelScript to write general programs much like how Python is used (more as a curiosity than looking to do what Python does in full). So without further adue, here is the: ARE (AngleScript Runtime Enviroment) Just drop any script in the "/scripts" directory, and execute it by typing it's name:
Quote: >hello.as
More than just being able to execute scripts, it also has all of the plug-ins compiled into it so it has a standard library of sorts. Also the script builder of course, so you can use includes and such. I know, I know, you're all wildly impressed :P But using the ARE I did some benchmarking (highly unscientifically) of AS vs C++. I only used one metric, and only did it 3 times, and I didn't take any significant precautions, so clearly... it's 100% the definitive last word on performance... for both languages. period. anyway here are the results:
Quote: =============== Primes 0 - 1000 =============== GNU/C++ 4.1.2 (MinGW) --------------------- Largest prime between 0 and 1000 is 997 Execution time: 0.000765181s AngelScript (Latest SVN) ------------------------ Largest prime between 0 and 1000 is 997 Execution time: 0.000726768s ================= Primes 0 - 100000 ================= GNU/C++ 4.1.2 (MinGW) --------------------- Largest prime between 0 and 100000 is 99991 Execution time: 0.0102656s AngelScript (Latest SVN) ------------------------ Largest prime between 0 and 100000 is 99991 Execution time: 0.249232s ==================== Primes 0 - 100000000 ==================== GNU/C++ 4.1.2 (MinGW) --------------------- Largest prime between 0 and 10000000 is 9999991 Execution time: 5.61898s AngelScript (Latest SVN) ------------------------ Largest prime between 0 and 10000000 is 9999991 Execution time: 183.455s
And here is the source code for both versions: First, C++

#include <iostream>

#include "hr_timer.h"

using namespace std;

int findLargestPrime( int topCandidate )
{
	int largestPrime = 0;
	int candidate = 2;

	while( candidate <= topCandidate )
	{
		int trialDivisor = 2;
		bool prime = true;
		while(trialDivisor * trialDivisor <= candidate)
		{
			if(candidate % trialDivisor == 0)
			{
				prime = false;
				break;
			}
			trialDivisor++;
		}

		if( prime )
			largestPrime = candidate;
		candidate++;
	}

	return largestPrime;
}

int main()
{
    CStopWatch timer;
    timer.startTimer();

    // ================================================================================

	int topCandidate = 10000000;

	int largestPrime = findLargestPrime( topCandidate );

	cout << "Largest prime between 0 and " << topCandidate << " is " << largestPrime << endl;

    // ================================================================================

    timer.stopTimer();
    cout << endl << "Execution time: " << timer.getElapsedTime() << "s" << endl;

	return EXIT_SUCCESS;
}

Now, AS:

int findLargestPrime( int topCandidate )
{
	int largestPrime = 0;
	
	int candidate = 2;
	while( candidate <= topCandidate )
	{
		int trialDivisor = 2;
		bool prime = true;
		while( trialDivisor * trialDivisor <= candidate )
		{
			if( candidate % trialDivisor == 0 )
			{
				prime = false;
				break;
			}
			trialDivisor++;
		}
		
		if( prime )
			largestPrime = candidate;
		candidate++;
	}
	
	return largestPrime;
}

int main()
{
	int topCandidate = 100000000;

	int largestPrime = findLargestPrime( topCandidate );
	
	print( "Largest prime between 0 and " + topCandidate + " is " + largestPrime + "\n" );
	
	return 0;
}

For the AS version, the timing is handled by the same C++ hr_timer but that is done in the ARE, the time to load and compile the script, and prepare the context, is not included in the timing. Now one last thing you all may find interesting, there is a cool blog post where a guy took tons of metrics for many many languages, and plotted the results on a graph of "CodeSize VS Speed", where the bottom left corner is the best of both worlds and the holy grail of all languages essentially. Lots of very expected results, like C++ being very fast, but large on code size, PHP/Ruby being slow as molasses but small on code. BUT!! One VERY interesting unexpected result! LUA sits very tight, at a very nice place on the graph, and LUA JIT sits in the NEAR IDEAL corner of the graph! Better averages than C++, Java, really anything. The only languages beating LUA JIT are OCMAL and one other. Still very interesting. I would be interested to see AS on here! http://gmarceau.qc.ca/blog/2009/05/speed-size-and-dependability-of.html
==============================
A Developers Blog | Dark Rock Studios - My Site
Advertisement
You might be interested in taking a look at eScript. It seems to have pretty much the features that you were looking for.

The performance numbers that you showed, seems reasonable for a scripting language. I will however take a look at the byte code that is generated for this to see if there is anything obvious that can be optimized.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement