Thread overview | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 25, 2007 FlowerScirpt teaser | ||||
---|---|---|---|---|
| ||||
Hi guys, several weeks ago while working on PHP (web based) project of mine I was very unhappy with PHP's performance. I decided to port the project to D, so I needed a scripting language for use with D. DMDScript is not free plus it is hell to extend. I found miniD but it was painfully slow. So I decided to write a new scripting engine. Now it is more ready than to not, so I want to check if there is more people interested besides me. If so we could turn this into a community project or something like that. To be more specific I've almost finished the engine itself, but it lacks stdlib. And to be a real PHP replacement it needs very good stdlib (luckily Tango got most of what we need <g>). So please tell me if there is someone interested in helping to design/implement stdlib and maybe optimize the engine even further. Here is a little benchmark I did and some more info about the engine. The engine is kind of mixture between JavaScript and D. Here is little something from my readme.txt which is work in progress. FlowerScript goals: As usable for web applications as PHP but faster (done) As simple and flexible as JavaScript (done) Easily extensible from D (mostly done) Embeddable in HTML (done) Built in encryption/decryption Usable outside web applications I like the simplicity and flexibility of JavaScript, I also like mootools, so I wanted FlowerScript similar to JavaScript. Instead of documenting everything (which I will also do if I have the time) I will describe the differences from JavaScript. In FS there is no term like "objects" or such. There are two types. Basic data types: 'boolean', 'string', 'number', 'null', 'undefined', 'void' and 'scopes'. Scopes are pretty much what JavaScript's objects are. You can put properties in them. You can use them as associative arrays. In addition scopes can also be called as functions. The only difference between a scope and a function, is that the function can accept named arguments. Arrays also derive from 'scope'. Other differences from JavaScript: Array slicing - "array[from..to]" . 'from' or 'to' may be omitted Strings can be indexed or sliced as arrays Scopes are callable. They act as annonymous functions Supports 'outer' keyword to access the outer scope Supports some special properties: .dup (duplicate), .dupr (duplicate recursively), .reverse (reverse array) Supports 'foreach' and 'foreachr'. The syntax for both is "foreach(forexpression) expression|statement", where 'forexpression' must evaluate to scope (arrays are scopes too). 'key' and 'value' are automatically defined (with these names) withing the foreach's scope No support for the following statements (this may change in future): in - not as flexible as foreach switch - it is useless as it does nothing more than if/else but with inconsistent syntax do, while - 'for' without semicolons will do the same as while. i.e. for(condition) instead of for(init;condition;dosomething) new, delete - to delete a variable use symbol=undefined; try, catch, finally - not implemented yet Supports 'goto'. The difference from C is that labels are not "label:" but "label expression;", where 'expression' is expression that evaluates to string. This seems more consistent and flexible. All variables but numbers are passed by reference instead of copy. Numbers are always copied. Other minor things to be added later... They may be other differences since I haven't studied the ECMAScript specifications... Little benchmark: FlowerScript (development version -O -inline) versus PHP 5.2.3 with ZendOptimizer 3.2.8 (zend_optimizer.optimization_level=15) Benchmarks are on the same PC PHP timing is done with microtime(), which means that this timing DOES NOT INCLUDE THE COMPILATION TIME, unlike FlowerScript which is summary of compilation (without caching) and execution. Tests: ================================================ /////////// ///Flower (time ranges from 0.017 to 0.016) /////////// $SERVER={"gosho":"pesho"};$COOKIE={"gosho":"pesho"}; for($c=0;$c<=1000;$c++) { $a=("gosho"~"["~$SERVER["gosho"]~"]"~"="~$SERVER["gosho"]~"<br />"); $b=("gosho"~"["~$COOKIE["gosho"]~"]"~"="~$COOKIE["gosho"]~"<br />"); } /////////// ///PHP (time ranges from 0.9 to 0.1, generally above 0.3) /////////// <?php $a=microtime(); $SERVER=array("gosho"=>"pesho");$COOKIE=array("gosho"=>"pesho"); for($c=0;$c<=1000;$c++) { $a=("gosho"."[".$SERVER["gosho"]."]"."=".$SERVER["gosho"]."<br />"); $b=("gosho"."[".$COOKIE["gosho"]."]"."=".$COOKIE["gosho"]."<br />"); } echo(microtime()-$a); ?> ================================================ So if you are interested give me a note and I will eventually start a dsource project. |
September 25, 2007 Re: FlowerScirpt teaser | ||||
---|---|---|---|---|
| ||||
Posted in reply to bobef | I would love to use for my webpage as soon as I have added every little feature my webpage needs. bobef Wrote:
> Hi guys,
>
> several weeks ago while working on PHP (web based) project of mine I was very unhappy with PHP's performance. I decided to port the project to D, so I needed a scripting language for use with D. DMDScript is not free plus it is hell to extend. I found miniD but it was painfully slow. So I decided to write a new scripting engine. Now it is more ready than to not, so I want to check if there is more people interested besides me. If so we could turn this into a community project or something like that. To be more specific I've almost finished the engine itself, but it lacks stdlib. And to be a real PHP replacement it needs very good stdlib (luckily Tango got most of what we need <g>). So please tell me if there is someone interested in helping to design/implement stdlib and maybe optimize the engine even further. Here is a little benchmark I did and some more info about the engine.
> The engine is kind of mixture between JavaScript and D. Here is little something from my readme.txt which is work in progress.
>
> FlowerScript goals:
> As usable for web applications as PHP but faster (done)
> As simple and flexible as JavaScript (done)
> Easily extensible from D (mostly done)
> Embeddable in HTML (done)
> Built in encryption/decryption
> Usable outside web applications
>
> I like the simplicity and flexibility of JavaScript, I also like mootools, so I wanted FlowerScript similar to JavaScript. Instead of documenting everything (which I will also do if I have the time) I will describe the differences from JavaScript.
> In FS there is no term like "objects" or such. There are two types. Basic data types: 'boolean', 'string', 'number', 'null', 'undefined', 'void' and 'scopes'. Scopes are pretty much what JavaScript's objects are. You can put properties in them. You can use them as associative arrays. In addition scopes can also be called as functions. The only difference between a scope and a function, is that the function can accept named arguments. Arrays also derive from 'scope'.
> Other differences from JavaScript:
> Array slicing - "array[from..to]" . 'from' or 'to' may be omitted
> Strings can be indexed or sliced as arrays
> Scopes are callable. They act as annonymous functions
> Supports 'outer' keyword to access the outer scope
> Supports some special properties: .dup (duplicate), .dupr (duplicate recursively), .reverse (reverse array)
> Supports 'foreach' and 'foreachr'. The syntax for both is "foreach(forexpression) expression|statement", where 'forexpression' must evaluate to scope (arrays are scopes too). 'key' and 'value' are automatically defined (with these names) withing the foreach's scope
> No support for the following statements (this may change in future):
> in - not as flexible as foreach
> switch - it is useless as it does nothing more than if/else but with inconsistent syntax
> do, while - 'for' without semicolons will do the same as while. i.e. for(condition) instead of for(init;condition;dosomething)
> new, delete - to delete a variable use symbol=undefined;
> try, catch, finally - not implemented yet
> Supports 'goto'. The difference from C is that labels are not "label:" but "label expression;", where 'expression' is expression that evaluates to string. This seems more consistent and flexible.
> All variables but numbers are passed by reference instead of copy. Numbers are always copied.
> Other minor things to be added later...
> They may be other differences since I haven't studied the ECMAScript specifications...
>
> Little benchmark:
>
> FlowerScript (development version -O -inline) versus PHP 5.2.3 with ZendOptimizer 3.2.8 (zend_optimizer.optimization_level=15)
> Benchmarks are on the same PC
> PHP timing is done with microtime(), which means that this timing DOES NOT INCLUDE THE COMPILATION TIME, unlike FlowerScript which is summary of compilation (without caching) and execution.
>
>
> Tests:
>
> ================================================
>
> ///////////
> ///Flower (time ranges from 0.017 to 0.016)
> ///////////
>
> $SERVER={"gosho":"pesho"};$COOKIE={"gosho":"pesho"};
> for($c=0;$c<=1000;$c++)
> {
> $a=("gosho"~"["~$SERVER["gosho"]~"]"~"="~$SERVER["gosho"]~"<br />");
> $b=("gosho"~"["~$COOKIE["gosho"]~"]"~"="~$COOKIE["gosho"]~"<br />");
> }
>
>
> ///////////
> ///PHP (time ranges from 0.9 to 0.1, generally above 0.3)
> ///////////
>
> <?php
> $a=microtime();
> $SERVER=array("gosho"=>"pesho");$COOKIE=array("gosho"=>"pesho");
> for($c=0;$c<=1000;$c++)
> {
> $a=("gosho"."[".$SERVER["gosho"]."]"."=".$SERVER["gosho"]."<br />");
> $b=("gosho"."[".$COOKIE["gosho"]."]"."=".$COOKIE["gosho"]."<br />");
> }
> echo(microtime()-$a);
> ?>
>
>
> ================================================
>
> So if you are interested give me a note and I will eventually start a dsource project.
|
September 25, 2007 Re: FlowerScirpt teaser | ||||
---|---|---|---|---|
| ||||
Posted in reply to bobef | "bobef" <bobef@abv_nospam.bg> wrote in message news:fdbs6o$r06$1@digitalmars.com... > I found miniD but it was painfully slow. Now, that's not entirely fair because I _did_ reply to your threads and offer suggestions (such as compiling with -release, which, BTW, about halves the execution time for the example you gave), but as far as I can tell you never even looked at them again. I've also been working on speeding up the interpreter, mostly because of your (and others') complaints. > $SERVER={"gosho":"pesho"};$COOKIE={"gosho":"pesho"}; > for($c=0;$c<=1000;$c++) > { > $a=("gosho"~"["~$SERVER["gosho"]~"]"~"="~$SERVER["gosho"]~"<br />"); > $b=("gosho"~"["~$COOKIE["gosho"]~"]"~"="~$COOKIE["gosho"]~"<br />"); > } I'd like to know how FlowerScript handles strings. Are they mutable? And if not, how do you get around the problem of allocating (at a bare minimum) 2000 strings in this loop? |
September 25, 2007 Re: FlowerScirpt teaser | ||||
---|---|---|---|---|
| ||||
Posted in reply to bobef | bobef wrote:
> Hi guys,
>
> several weeks ago while working on PHP (web based) project of mine I was very unhappy with PHP's performance. I decided to port the project to D, so I needed a scripting language for use with D. DMDScript is not free plus it is hell to extend. I found miniD but it was painfully slow. So I decided to write a new scripting engine. Now it is more ready than to not, so I want to check if there is more people interested besides me. If so we could turn this into a community project or something like that. To be more specific I've almost finished the engine itself, but it lacks stdlib. And to be a real PHP replacement it needs very good stdlib (luckily Tango got most of what we need <g>). So please tell me if there is someone interested in helping to design/implement stdlib and maybe optimize the engine even further. Here is a little benchmark I did and some more info about the engine.
> The engine is kind of mixture between JavaScript and D. Here is little something from my readme.txt which is work in progress.
I'd rather dig into MiniD and help improve the performance than creating a new scripting engine. Code duplication for a language that has PHP's limitations just isn't worth anything, IMHO. *shrug*
|
September 26, 2007 Re: FlowerScirpt teaser | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley Wrote: > "bobef" <bobef@abv_nospam.bg> wrote in message news:fdbs6o$r06$1@digitalmars.com... > > I found miniD but it was painfully slow. > > Now, that's not entirely fair because I _did_ reply to your threads and offer suggestions (such as compiling with -release, which, BTW, about halves the execution time for the example you gave), but as far as I can tell you never even looked at them again. I've also been working on speeding up the interpreter, mostly because of your (and others') complaints. > I am sorry it looks like that. I've read all your answers in the threads back then, but I haven't looked at the MiniD after I decided to write engine from scratch. I believe you did improvements and maybe it is faster now. It would be nice if you post some benchmarks. But back then, the benchmark I did took 50milisecs for 100 loops (optimized and inlined) and mine takes 17milisecs for 1000 loops with more concats. By the way I have different PC now (it is almost the same as the old one but just for the record)... Sorry, I shouldn't have said "painfully slow", because it isn't really that slow. What I meant is "slower than my needs require". > > $SERVER={"gosho":"pesho"};$COOKIE={"gosho":"pesho"}; > > for($c=0;$c<=1000;$c++) > > { > > $a=("gosho"~"["~$SERVER["gosho"]~"]"~"="~$SERVER["gosho"]~"<br />"); > > $b=("gosho"~"["~$COOKIE["gosho"]~"]"~"="~$COOKIE["gosho"]~"<br />"); > > } > > I'd like to know how FlowerScript handles strings. Are they mutable? And if not, how do you get around the problem of allocating (at a bare minimum) 2000 strings in this loop? > > I don't know what is "mutable", sorry for my poor English. The only mutable thing that I know is my sound card :D I will try to explain, though. I do compile time optimizations that "sees" that there are several concats (or any other binary operator) in a row so instead of creating several new string objects it creates only one. Furthermore the cat operator counts the length of the resulting string (or array) and does only one allocation, so I haven't profiled it (yet) but in these loop there are like 2 allocations times 1000... This is 2000 allocations and another 2000 .dup-s... I guess D is fast :D This is all I do and can remember of... I will release the source soon, which is less than 100k at the moment, and you will see for yourself if you are interested. I guess the reason it being relatively fast is because the whole engine is some kind lightweight... |
September 26, 2007 Re: FlowerScirpt teaser | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexander Panek | Alexander Panek Wrote:
> Code duplication for a language that has PHP's limitations just isn't worth anything, IMHO. *shrug*
I agree and I am not creating language that has PHP's limitations. PHP is great for the web because it it has great stdlib and is easy to embed, but as programming language (IMO) it sucks. FlowerScript is not PHP. It is more like a JavaScript + some D features - some features I find useless + few small changes of my own. So it is very dynamic, like JavaScript and unlike PHP. Sorry if I am not using the right terms here, I hope you understand what I mean when I say "dynamic".
|
September 26, 2007 Re: FlowerScirpt teaser | ||||
---|---|---|---|---|
| ||||
Posted in reply to bobef | bobef Wrote:
>It would be nice if you post some benchmarks.
I mean comparisons to other languages.
|
September 26, 2007 Re: FlowerScirpt teaser | ||||
---|---|---|---|---|
| ||||
Posted in reply to bobef | I felt bad I accusing MiniD in slowness so I did the same test with MiniD from trunk and it is actually faster. This example takes 7.5 millisecs on my PC. D: import tango.text.Util; import tango.io.File; import minid.minid; import minid.types; void main() { auto a=new tango.util.time.StopWatch.StopWatch; a.start(); auto context = NewContext(); scope auto f=new File("test.md"); dchar[] buf=tango.text.convert.Utf.toUtf32(cast(char[])f.read()); loadModuleString(context.mainThread,buf,null,"test.md"); tango.io.Console.Cout("\n\n\n"~tango.text.convert.Float.toUtf8(a.stop())); } MiniD: module test; global SERVER={gosho="pesho"}; global COOKIE={gosho="pesho"}; for(local c=0;c<=1000;c++) { local a=("gosho"~"["~SERVER["gosho"]~"]"~"="~SERVER["gosho"]~"<br />"); local b=("gosho"~"["~COOKIE["gosho"]~"]"~"="~COOKIE["gosho"]~"<br />"); } |
September 26, 2007 Re: FlowerScirpt teaser | ||||
---|---|---|---|---|
| ||||
Posted in reply to bobef | Well, even the fact that it seems to use the dollar sign as variable prefix makes me go puke. Really. There are so many good languages out there, why do you need create a new, incompatible and most probably unsupported one? Rather use MiniD, Ruby, Python, or what not else, as they are actively developed and not just a small hack to get some more performance for a website. |
September 26, 2007 Web, scripting languages & performance [Was: FlowerScirpt teaser] | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexander Panek | Alexander Panek <a.panek@brainsware.org> wrote: > Well, even the fact that it seems to use the dollar sign as variable prefix makes me go puke. Really. There are so many good languages out there, why do you need create a new, incompatible and most probably unsupported one? Rather use MiniD, Ruby, Python, or what not else, as they are actively developed and not just a small hack to get some more performance for a website. > If performance plays an important role, I wonder why nobody mentioned lua. (I did never really work with it but some voices say its quite fast, flexible and extensible with 'native code'). Also I have the feeling lots of people inseperable connect web programming with scripting languages. I see no real reason for not using plain D, maybe with a well-thought web-framework/library for web-apps. I mean especially web-apps require a good performance and if you remember that still lot of apps use CGI it is gruesome to re-load an interpreter every request. (I know there are lots of coutermeasures you can take against this problem, I just wanted to show the extreme case) Concerning security there ARE good reasons why you wouldnt want to write your webapp in C++ or C, you almost pre-programmed buffer overflows then. But D is lots more secure by design and if you look at PHP, you see that a scripting host does not always liberate you from buffer-overflows or other attacks. I would love such a framework. I'm also wondering if there might be a way to avoid that awful stateless coding style, ie to be able to do something like: ---- ask_for_users_address(); // user gets a form to enter its address, program here is "frozen" here // until the user submits or the session times out ask_for_users_bank_account(); // present another form ---- Henning -- GPG Public Key: http://keyserver.ganneff.de:11371/pks/lookup?op=get&search=0xDDD6D36D41911851 Fingerprint: 344F 4072 F038 BB9E B35D E6AB DDD6 D36D 4191 1851 |
Copyright © 1999-2021 by the D Language Foundation