• PHP vs LuaJIT
    39 replies, posted
Open your eyes. There already is a script-based solution 2 times faster than php and with simpler syntax. Only one disadvantage - there is no ready integration with apache, you must integrate it yourself. Some code to compare: MD5 performance tests [code]<?php $start = microtime(TRUE); for ($i = 1; $i <= 1000000; $i++) { md5("omgtest"); } echo(microtime(TRUE)-$start); /* ~1second */ ?>[/code] [code]--Lua local start = os.clock() for i=1,1000000 do md5.sumhexb("omgtest") end print(start-os.clock()) --~0.45s[/code] How shitty arrays in php are: [code]/* PHP foreach example 3: key and value */ $a = array( "one" => 1, "two" => 2, "three" => 3, "seventeen" => 17 ); foreach ($a as $k => $v) { echo "\$a[$k] => $v.\n"; } /* foreach example 4: multi-dimensional arrays */ $a = array(); $a[0][0] = "a"; $a[0][1] = "b"; $a[1][0] = "y"; $a[1][1] = "z"; foreach ($a as $v1) { foreach ($v1 as $v2) { echo "$v2\n"; } }[/code] [code]--the same in Lua local a = {one = 1, two = 2, three = 3, seventeen = 17} for k,v in pairs(a) do print(a[k].."=>"..v) end local a = {{'a','b'},{'y','z'}} for _,v in ipairs(a) do for _,v2 in ipairs(v) do print(v2) end end[/code] These $s are 100% useless and that's why PHP sucks [code]$variable_name = "blablavar"; $blablavar = "Hello, world!"; var_dump($$variable_name); $string = $string1.$string2."some string".$number."<br>';[/code] [code]--the same in Lua local varname = "table" local varname2 = "concat" local testtable = {'a',' testing',' apple'} print(_G[varname][varname2](testtable,'')) --a testing apple --probably we could use even local varname = "table.concat" local var1 = 123 local var2 = "omg hax" local var3 = 456 print(var1..var2..var3)[/code] Additionally, PHP stores almost all functions in global namespace, that makes it insanely slow to lookup correct function. In Lua, most libraries have their own table with functions. Memory usage: httpd with mod_dav (svn server) - 12 mb httpd with php - 30 mb luajit with http server and gd graphics lib - 4.5 mb
It depends what you are used to.
While PHP may not be incredible, it serves my purposes fine and so I'm quite happy to stick with it. Although I do like JSON-style syntax for objects/arrays.
PHP does not suck. Lua is crap compared to it.
[QUOTE=kna_rus;20340655]Open your eyes.[/QUOTE] I whole-heartedly agree. It's strange that people still use PHP when there are such great dynamic languages out there like Lua, Ruby and Python. The StackOverflow discussion on this ended in "poor programmers are quick to blindly defend their language". Figures. [QUOTE=kna_rus;20340655]There already is a script-based solution 2 times faster than php and with simpler syntax.[/QUOTE] [url=http://www.timestretch.com/FractalBenchmark.html]It's way faster than two times[/url]. And if you're referring to LuaJIT (there's no such thing as JITLua), it's even faster. [QUOTE=kna_rus;20340655] [code] for k,v in pairs(a) do print(a[k].."=>"..v) end [/code] [/QUOTE] a[k] == v. I think you mean just 'k'. Also, seeing as you're only using that table once, it's arguably better to express it like this: [lua] for k,v in pairs{one = 1, two = 2, three = 3, seventeen = 17} do print(("%s => %s"):format(k, v)) end [/lua] [QUOTE=kna_rus;20340655] print(_G[varname][varname2](testtable,'')) --a testing apple [/QUOTE] This is not syntactically sane... did you mean "" for the second argument? If so, that's the default value, so you don't need to pass a second argument in this case. [QUOTE=kna_rus;20340655] --probably we could use even local varname = "table.concat" [/QUOTE] You couldn't. Not sure why you'd imagine that would work. edit: Oh, and you can use [noparse][lua][/lua][/noparse] tags for highlighed Lua code. [QUOTE=ddrl46;20341221]PHP does not suck. Lua is crap compared to it.[/QUOTE] Is that really all you have to say? You realise how you much of a mindless fanboy you look like putting it like that? I guess there's not much that can be said in PHP's defense, though.
Sure there are faster things out there, but PHP is like industry standard...
PHP is pretty easy, I'll stick with that.
Indeed, PHP is pretty easy. Is it any easier than any of the other dynamic languages? Nope. The syntaxes of languages like Lua and Python are arguably even easier. It just happened to be presented in a very convenient way for hypertext preprocessing back when web server scripting was mostly done with Perl/CGI, with the inline php tags and short tags and everything. There also weren't a lot of alternatives back then, Perl was pretty widespread but Perl is not a very good example of a simple dynamic language. If you still want to defend PHP on the grounds that everyone is using it, sure. But why claim it's better than all the other, beautiful languages out there when you're literally not presenting a single argument?
Oh, a mistake. But it is still Just-In-Time Lua. Those performance test were done on my PC with LuaJIT 2.0 and Apache/2.2.4 (Win32) PHP/5.2.12. That was md5, at some other things, like fractal calculation, Lua may get even more speed. Lua has simpler syntax that is easy to understand, better table handling, metatables instead of shitty classes (in C++ classes don't suck, but in PHP...), global namespace free of random functions you may never use, even support for limiting script execution time (the way it is done in gmod just sucks), and a lot more cool features. If you want to add some more modules, you don't need to recompile whole Lua, just compile your module as dll (or whatever is used on linux) and load it. But the problem is that PHP is really industry standard. No hosting provides LuaJIT as base for CGI scripts, however documentation of GD library references "a cgi script that draws an analog clock with lua and lua-gd" and so on. As for Python, I wouldn't call it "easy", but it is still better that PHP. And that PHP script did $a[$k], just like Lua testtable[k].
[QUOTE=kna_rus;20343523]Those performance test were done on my PC with LuaJIT 2.0 and Apache/2.2.4 (Win32) PHP/5.2.12. That was md5, at some other things, like fractal calculation, Lua may get even more speed.[/QUOTE] The problem with your benchmark is that it calls a function that's most likely defined in C in both languages, thus making it completely pointless as a benchmark because the results depend almost entirely on the efficiency of the md5 algorithm deployed. [QUOTE=kna_rus;20343523]Lua has simpler syntax that is easy to understand, better table handling, metatables instead of shitty classes (in C++ classes don't suck, but in PHP...), global namespace free of random functions you may never use, even support for limiting script execution time (the way it is done in gmod just sucks), and a lot more cool features.[/QUOTE] Yeah, prototype-based object oriented programming is pretty cool, and a lot easier to teach a newbie than a class-based system, too. Especially in Lua where objects are so amazingly light, but it applies to JavaScript too (I can't really think of any other popular programming languages with object prototypes). [QUOTE=kna_rus;20343523]But the problem is that PHP is really industry standard. No hosting provides LuaJIT as base for CGI scripts, however documentation of GD library references "a cgi script that draws an analog clock with lua and lua-gd" and so on.[/QUOTE] Yeah, you can always host your own, though. There are a lot of good web servers out there with Lua support. I'm loosely working on one myself. [QUOTE=kna_rus;20343523]As for Python, I wouldn't call it "easy", but it is still better that PHP.[/QUOTE] Are you kidding me? Python has the most simplistic syntax ever. A lot of the other stuff isn't as immediately intuitive (__init__? ...really, Python?), granted, but indeed, it's a lot better than PHP. [QUOTE=kna_rus;20343523]And that PHP script did $a[$k], just like Lua testtable[k].[/QUOTE] Ah so you were just demonstrating for-each in both languages. I'm just used to seeing "=>" used for key-value pairs :v:
[QUOTE=nivek;20343276]PHP is pretty easy, I'll stick with that.[/QUOTE] Try out something like Django or Rails to see what "easy" really means.
[QUOTE=kna_rus;20340655] [code] /* foreach example 4: multi-dimensional arrays */ $a = array(); $a[0][0] = "a"; $a[0][1] = "b"; $a[1][0] = "y"; $a[1][1] = "z";[/code][/QUOTE] lol what are you doing
Php is easier to implement on the web, so it's more popular. No one wants to use cgi to use their Lua code. Don't get me wrong, I love Lua and if there was a way to have it work like php n the web, id be first in line. I might be out of date here, I need to check out mod_lua for apache properly maybe you can do website.com/somehing.lua
You can if you add a handler in Apache's configuration file.
[QUOTE=Diaklu;20350636]You can if you add a handler in Apache's configuration file.[/QUOTE] Sweet :D I've no idea but can Lua do stuff like PHP header() etc? (assuming it can't): That's where PHP wins over Lua for websites, because PHP was built for websites, Lua was not.
Don't know about that, I've never been able to compile mod_lua for Apache/2.2.9. There's not an awful lot about it on the internet apart from the official website.
Nothing I'd get too excited over, though it's cool regardless.
PHP is the standard right now, and it is what is mostly available a webservers. If you have a hosting package it will come with PHP and not LUA or Ruby or Python (sometimes). From that stand point it would be the better language to learn albeit not the fastest one out there.
[QUOTE='-[ Fizzadar ]-;20353630'](assuming it can't): That's where PHP wins over Lua for websites, because PHP was built for websites, Lua was not.[/QUOTE] That's a trash argument. PHP was designed for websites, but the way it encourages web developers to work by default is horrible. Languages like Python or Ruby were not designed exclusively for the purpose, but they still do a much better job. The only advantage PHP has is that you can drag and drop whatever scripts to your WWW root and it'll be executed. Not a fan of Lua, but assuming that you're using [url=http://keplerproject.org]Kepler[/url], [url=http://www.keplerproject.org/cgilua/reference.html#headers]CGILua.Headers[/url] [quote]PHP is the standard right now, and it is what is mostly available a webservers. If you have a hosting package it will come with PHP and not LUA or Ruby or Python (sometimes). From that stand point it would be the better language to learn albeit not the fastest one out there.[/quote] [b]No.[/b] If you're building any web application that gets popular in the first place, you'll have to move out of shared hosting and language availability is not a concern. (Besides, many hosts already support numerous other languages like Python and Ruby!)
Foreach examples were taken directly from official PHP manual. As for integration with apache, you can run http server even in Lua itself, and it may be faster that doing it in any other way. You CAN make something like header() in Lua, if server is running from Lua itself then it is easy, and if Lua is apache mod, then it depends on mod.
[QUOTE='-[ Fizzadar ]-;20350067']Php is easier to implement on the web, so it's more popular. No one wants to use cgi to use their Lua code. Don't get me wrong, I love Lua and if there was a way to have it work like php n the web, id be first in line. I might be out of date here, I need to check out mod_lua for apache properly maybe you can do website.com/somehing.lua[/QUOTE] CGI is indeed pretty lame. I'm working on a web server where Lua is deployed much like PHP, but I'd be surprised if I was the first to do so. I couldn't find anything with a simple Google search though. There's a Lua server with CGI capabilities in pure Lua called Xavante... I thought it supported mixed HTML and Lua, but apparently not. [QUOTE='-[ Fizzadar ]-;20353630']Sweet :D I've no idea but can Lua do stuff like PHP header() etc? (assuming it can't): That's where PHP wins over Lua for websites, because PHP was built for websites, Lua was not.[/QUOTE] That has nothing to do with the language. That's just the platform the language is running on; and yes, you could do the same in Lua.
Why doesn't anyone think of FastCGI? Oh and also [url]http://oss.digirati.com.br/mod_lua/2.0/handler.html[/url]. Sounds like there's builtin support for sending headers (would be strange if not)
Lua still needs to come quite a way before it's ready for this sort of thing, I believe. For now I'm looking into stuff like precompiled PHP like Facebook is rolling out, that's awesome.
I still much prefer PHP.
[QUOTE='-[ Fizzadar ]-;20372161']Lua still needs to come quite a way before it's ready for this sort of thing, I believe.[/QUOTE] ... are you insinuating Lua is missing something important? The language has been stable for years now, there's a reason it changes so slowly these days. It's more or less complete.
[QUOTE=jA_cOp;20375738]... are you insinuating Lua is missing something important? The language has been stable for years now, there's a reason it changes so slowly these days. It's more or less complete.[/QUOTE] I just meant things like the header() function, which is pretty much essential for a lot of PHP development. I wouldn't want it to become function-bloated like PHP obviously, but a http header set of functions would be great. I'm sure there's other things too.
[QUOTE='-[ Fizzadar ]-;20375880']I just meant things like the header() function, which is pretty much essential for a lot of PHP development. I wouldn't want it to become function-bloated like PHP obviously, but a http header set of functions would be great. I'm sure there's other things too.[/QUOTE] Yeah, but again, this has nothing to do with either Lua or PHP. What you're trying to say is that a good Lua web platform needs to appear before it can do the same job as PHP. In which case I agree.
[QUOTE='-[ Fizzadar ]-;20375880']I just meant things like the header() function, which is pretty much essential for a lot of PHP development.[/QUOTE] [b]What on earth are you talking about[/b]? Any web framework for Lua supports sending headers to the browser - that's a fucking necessity to allow them to send pages to the browser! You're missing the point here - with something like Lua or Python, you have to use a separate framework that provide their own methods for things like header() in PHP. That does not make them inferior. To clarify even more, the simplest way to get up a web application in, say, Python would be to write your own [url=http://en.wikipedia.org/wiki/Web_Server_Gateway_Interface]WSGI handler[/url] and build all the necessary classes (templating, database access) yourself and glue your application together. Or you could download Django, work on your app locally and use one of the many supported deployment methods.
While we're on the subject of ditching PHP, let me throw in an alternative: C# on ASP.NET It's insanely fast, strongly and statically typed (this catches [b]alot[/b] of silly coding errors), and provides so many useful features thanks to the ASP.NET framework. Those of you who say "burrr, It's Windows only, no thanks!", you can ditch that argument thanks to mod_mono, and MonoDevelop. If you have the privilege of having a Windows dev machine and a Windows server, then you can get started with ASP.NET for free. Microsoft provides an express version of Visual Web Developer (which is excellent), and all Windows Servers already come with IIS. Setting up IIS to serve ASP.NET webapps is a snap, just install the framework, setup the website in IIS, and you're laughing.
Good luck finding a job as as a LUA web programmer.. I think the demand for programmers in PHP, ASP.net, ruby etc. is alot bigger than LUA web programmers.. Don't get me wrong, your precious LUA might beat PHP when it comes to speed, but don't forget that PHP includes TONS of usefull stuff (Like database drivers for more or less all types of databases) so you don't have to waste time writing your own. Thus saving your employer money and time. (Cost-benefit is important for most companies and the 0.0000001 second advantage of using LUA simply isn't viable) The only real arguments you come with is syntax (wich can be a matter of preference) and speed (Which isn't a big dealio if you configure your server properly)
Sorry, you need to Log In to post a reply to this thread.