Street Fight: PHP vs Java (Part 1)
Please welcome our newest regular GJ blogger: The Blackdood
Ooooo! fight! fight! fight!.
This is a fight that has been going on for as long as I can remember. Some say Java is too heavy, some say PHP is too light. I'm here to tell you how it is.
To be fair, I was first a Perl programmer, and that didn't last long. I then moved to PHP3. I was a PHP developer up until about a year ago, straight through PHP5. Now, I develop for both. I have managed teams of both PHP developers and Java developers, and developed large scale applications in both.
PHP has come a long way since the days of version 3. The new object model is a step in the right direction, and OO programming is no longer as big of a performance hog. As a result, a ton of PHP frameworks have started popping up. The one I've used the most is Symfony (
http://www.symfony-project.com), it's basically a port of RoR. The Java framework I am using is WebWork (
http://www.opensymphony.com/webwork/).
This is the first article of many to come. This first one will cover VERY basic performance results, and we'll get more detailed as time goes on and users request. What I will be focusing on is ACTUAL development with, not the actual benchmark results
Now, let's get the numbers out of the way. I did some minor benchmarking, but we all know that benchmarks don't really prove much as it can EASILY be swayed in one direction or another. These are just very basic operations, not going to benchmark the frameworks because that's unfair. I'll explain why later.
I tested : Apache Webserver + mod_php5 and Zend vs Resin 3.0.19 w/ JDK5 on a Dual Core Intel Mac 1.5 gigs of RAM.
For testing I used ab (apachebench) which comes default with every apache installation. Basically a "dumb" client that hits a URL as fast as it can.
The command was:
ab -c 50 -n 10000
Which means, do 50 requests at a time, and complete 10,000 requests. This test isn't exactly the best because it's not really doing anything. Really only testing who can loop faster. Results are interesting though.
The scripts:
JSP:
<%
for(Integer i =0; i < 10000; i++)
{
out.println((i % 10));
}
%>
PHP
<?php
for($i =0; $i < 10000; $i++)
{
echo $i % 10;
}
?>
PHP Results:
260.68 requests per second. Took 38 seconds to service 10000 requests (50 concurrent users at a time)
/resin/webapps/benchmarks jgagner$ ab -c 50 -n 10000 http://localhost/~jgagner/benchmark1.php
This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests
Server Software: Apache/1.3.33
Server Hostname: localhost
Server Port: 80
Document Path: /~jgagner/benchmark1.php
Document Length: 10000 bytes
Concurrency Level: 50
Time taken for tests: 38.361 seconds
Complete requests: 10000
Failed requests: 0
Broken pipe errors: 0
Total transferred: 101834793 bytes
HTML transferred: 100161954 bytes
Requests per second: 260.68 [#/sec] (mean)
Time per request: 191.80 [ms] (mean)
Time per request: 3.84 [ms] (mean, across all concurrent requests)
Transfer rate: 2654.64 [Kbytes/sec] received
Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 19 28.6 4 166
Processing: 9 171 102.5 163 1117
Waiting: 0 170 102.9 162 1116
Total: 9 190 101.8 173 1117
Percentage of the requests served within a certain time (ms)
50% 173
66% 208
75% 233
80% 250
90% 298
95% 386
98% 490
99% 543
100% 1117 (last request)
JSP results:
1010.61 requests per second, or 9.85 seconds to service 10,000 requests (50 at a time)
/resin/webapps/benchmarks/WEB-INF jgagner$ ab -c 50 -n 10000 http://localhost:8080/benchmarks/benchmark1.jsp
This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests
Server Software: Resin/3.0.19
Server Hostname: localhost
Server Port: 8080
Document Path: /benchmarks/benchmark1.jsp
Document Length: 20000 bytes
Concurrency Level: 50
Time taken for tests: 9.895 seconds
Complete requests: 10000
Failed requests: 0
Broken pipe errors: 0
Total transferred: 202307479 bytes
HTML transferred: 200116165 bytes
Requests per second: 1010.61 [#/sec] (mean)
Time per request: 49.47 [ms] (mean)
Time per request: 0.99 [ms] (mean, across all concurrent requests)
Transfer rate: 20445.42 [Kbytes/sec] received
Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 1.5 0 26
Processing: 5 49 44.8 46 618
Waiting: 2 48 44.8 45 617
Total: 5 49 44.7 46 618
Percentage of the requests served within a certain time (ms)
50% 46
66% 49
75% 51
80% 52
90% 60
95% 86
98% 203
99% 313
100% 618 (last request)
Wow, amazing isn't it!? Remember kids, benchmarks don't always tell the whole story. We'll find out why next episode. If you have any comments or suggestions you may write me, jerome AT blackdood DOT com.
Holla back, youngin.
Blackdood
分享到:
相关推荐
LOD1:2396 个三角形 LOD2:448 个三角形 支持 PBR 纹理,提供更真实的材质效果。 所有节点、材质和纹理都有适当的命名,便于管理和使用。 角色模型具有良好的绑定,便于动画制作。 用户可以选择隐藏角色的头盔部分...
在Java编程中,JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,常用于前后端数据传输。当你从服务器接收到一个JSON格式的字符串,可能需要将其转换为Java对象以便于处理。这个过程通常称为反序列化...
### Java 数据格式转换成 JSON 的全面解析 #### 一、JSON 概述 JSON (JavaScript Object Notation) 是一种轻量级的数据交换格式,最初由 Douglas Crockford 提出。它基于 JavaScript 的语法,但独立于任何编程语言...
Java中的OpenStreetMap路由实现 这是我对大学小组项目的贡献。 代码包括客户端和服务器端。 XML 格式的 OpenStreetMap 数据从“xml”文件夹加载。 该实现包括几种不同的路由算法(Dijkstra、AStar 和双向 Dijkstra ...
1. **Java GUI框架**:Java地图编辑器通常基于Java Swing或JavaFX等图形用户界面库构建。这些库提供了丰富的组件,如按钮、文本框、面板等,用于构建用户友好的界面。 2. **地图渲染**:编辑器需要能够将地图数据...
Java对象与JSON之间的转换在现代Web开发中至关重要,因为它们是服务器端数据处理和客户端交互的主要格式。Gson是Google提供的一个开源库,专门用于在Java对象和JSON数据之间进行无缝转换。它以其强大、灵活和高效而...
Java对象与JSON字符串之间的转换是Java开发中常见的需求,特别是在处理前后端交互或者存储数据时。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,易于人阅读和编写,同时也方便机器解析和生成。本...
1. **数据读取与解析**:osm-util 可以解析 .osm XML 文件,并将其转化为易于处理的 Java 对象。这使得开发者能够快速访问和操作 OSM 数据,而无需自己编写复杂的 XML 解析代码。 2. **数据过滤与筛选**:通过 osm-...
BasicOSMParser 是一组 Java 类,允许解析原始 OSM XML 文件。 然后您就可以在您的程序中操作这些 Java 对象。 您还可以将数据导出为 CSV 文件。 这个库非常容易理解。 它使用默认的 Java SAX 解析器 (org.xml.sax)...
JOSM(Java OpenStreetMap编辑器,英语:Java OpenStreetMap Editor)是开放街图地理信息的自由编辑工具,以Java撰写。其有许多高级的功能,但是也比默认的iD线上编辑器有较复杂的用户界面。 JOSM有一些重要的功能,...
OpenStreetMap(OSM)是一个开放源代码的全球地理数据项目,它允许用户贡献和编辑地图信息。在处理OSM数据时,`osmconvert`是一个非常有用的工具,尤其适用于转换和处理这些数据。这个工具是由OSM社区开发的,主要...
1. **序列化**:将Java对象转换为JSON字符串。 2. **反序列化**:将JSON字符串解析回等效的Java对象。 ### 添加Gson依赖 首先,确保你的项目包含Gson库。如果你使用Maven,添加以下依赖到`pom.xml`文件中: ```xml ...
1. **序列化:Java对象到JSON** 要将一个Java对象转换为JSON字符串,我们可以使用`ObjectMapper`的`writeValueAsString()`方法。假设我们有一个简单的User类: ```java public class User { private String name;...
1. 数据预处理:使用Java读取和解析地理空间数据,例如,你可以加载一个GeoTIFF文件,将其转化为Geotools支持的GridCoverage2D对象。 2. 等值线生成:利用Geotools的WContour模块,根据数据的特性设置合适的等值...
【标题】"lib_java失物招领系统_street3z8_gooseq6z_" 指的是一款基于Java开发的失物招领系统,其中包含了特定的开发者标识street3z8和gooseq6z。这个系统的核心目标是提供一个平台,方便用户查找丢失的物品,同时也...
1. **Java GUI框架**:首先,你需要选择一个Java GUI框架来构建用户界面。Swing是Java的标准库之一,提供了丰富的组件库,如JFrame、JPanel和JLabel等,可以用来创建窗口和控件。JavaFX则提供更现代的外观和更多的...
1. **数据下载**:首先,你需要从OpenStreetMap官方网站或其他提供OSM数据的服务下载特定区域的地图数据。这些数据可能以.osm或.pbf格式提供。 2. **数据转换**:由于SuperMap iObject Java直接处理二进制OSM数据...
1. **Java基础** - **Java SE**:Java标准版(Java SE)是开发电子地图系统的基础,提供了诸如集合框架、多线程、网络编程等核心功能。 - **Swing/AWT**:用于构建用户界面的库,Swing提供了丰富的组件,如JFrame...
1. **OpenStreetMap数据支持**: GraphHopper默认使用OpenStreetMap(OSM)数据作为基础地图信息。OSM是一个全球性的、由志愿者维护的地理数据库,包含了道路、建筑、交通设施等多种地理信息。GraphHopper能够解析...
1. **Java核心技术**: - **Java基础**:项目基于Java SE(标准版)平台,利用Java的基础语法、类库和API进行开发。 - **Swing或JavaFX**:作为GUI构建工具,可能使用了Swing或JavaFX来创建地图界面,这两个都是...