[2012-02-27] Checking If File Exists On Remote Server performance test - PHP
Had to work a bit on a performance of some script which checks files on remote server. Different sources on the internet says different things about which one is the fastest method so had to try it myself.
method fopen(): 75.279833As I thought cURL is fastest one but what surprised me is that fopen() wasn't that bad as I expected.
method getimagesize(): 293.342770
method file_get_contents(): 323.601692
method get_headers(): 80.516780
method cURL: 43.12145
And here the code I used for test:
$url = 'http://Some_File_Here.jpg';
$times = array();
$methods = array('fopen',
'GetImageSize',
'file_get_contents',
'get_headers',
'curl');
foreach($methods as $method){
$time = gettimeofday();
for($i=1;$i<=100;$i++){
switch($method){
case 'fopen':
fopen($url, 'r');
break;
case 'GetImageSize':
GetImageSize($url);
break;
case 'file_get_contents':
file_get_contents($url);
break;
case 'get_headers':
strstr(current(get_headers($url)), '200');
break;
case 'curl':
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
break;
}
}
$tmp = gettimeofday();
$sec = $tmp['sec']-$time['sec'];
$usec = $tmp['usec']-$time['usec'];
if($usec<0){$sec--; $usec+=1000000;}
$times[] = 'method '.$method.': '.$sec.'.'.$usec;
}
foreach($times as $t)
echo $t.'<br />';
[2011-07-06] New domain :D
Today I bought new domain for my personal website.
Also my e-mail address has been changed, new one is of course in contact section.
And with new domain there will be lots of changes in here soon.
[2011-03-12] File Name Changer
It's been a while since last post here, but I've been busy with my thesis. Lately had idea to clean up the mess on my HDD, especially my music collection, for that purpose I've made this little application.
It has a few basic functions for changing multiple file's names at once.
It's made in Java SE ofcourse :D with Nimbus look and feel so JRE 6 update 10 is required to run it.
File Name Changer is available to download HERE.
I wonder if you will like it :)
[2011-01-10] OBJ files viewer (JOGL)
Lately I've made simple OBJ file viewer, it's made in Java and you can run it under windows x86 and x64 (if u have libraries for other OS go ahead). It ain't so great but it's main purpose is to learn how OBJ files loading works. There are simple control functions so it makes this little program more fun.
1 - points mode
2 - lines mode
3 - faces mode
4 - shadows flat/smooth
5 - colors on/off
6 - textures on/off
7 - next texture
8 - previous OBJ file
9 - next OBJ file
0 - auto move
W,S,A,D,Q,E - translation
NUMPAD (4,5,6,7,8,9) - rotation
-, = - scaling

It might crash sometimes because of large amount of vertices in some obj files I've used, but you can remove them and put yours instead (just delete, swap or add more files to obj directory) the same thing goes for textures (delete, swap or add more textures to img directory). Also some objects are large (1st obj file is) so use S key to go back or dash key to make them smaller so you can see whole object.
You can download it here OBJ file viewer, I hope someone will learn something from it.
Archive includes source code in directory org\eu\wolv, obj files in obj directory and textures in img directory, in main directory I've made bat files for jar compiling and packing and for running it under windows.
[2010-12-24] JOGL - FPS camera (fixed and dynamic)
Today I wanna show you how to implement FPS camera with Java OpenGL.
This camera is fixed so we move whole „world” and rotate it while we are standing still and looking in one direction.
public void camFixed(float xKey, float yKey, float zKey, float xMouse, float yMouse){Another way to get the same effect is dynamic camera where “world” stands still and we are moving and turning around, just like in real life.
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45f, 2, 0.1f, 500);
// Forward & back while follow lookat point
xAt -= (float) Math.sin(Math.toRadians(xMouse)) * zKey *
// fly up & down follow lookat point
(float) Math.cos(Math.toRadians(yMouse)) +
// Left & right while looking perpendiculary at lookat point
(float) Math.sin(Math.toRadians(xMouse - 90)) * xKey;
zAt += (float) Math.cos(Math.toRadians(xMouse)) * zKey *
(float) Math.cos(Math.toRadians(yMouse)) +
(float) Math.cos(Math.toRadians(xMouse - 90)) * xKey;
// fly up & down // fly up & down follow lookat point
yAt += yKey + (float) Math.sin(Math.toRadians(yMouse)) * zKey;
gl.glRotatef(yMouse, 1, 0, 0);// Vertical rotation
gl.glRotatef(xMouse, 0, 1, 0);// Horizontal rotation
gl.glTranslatef(xAt, yAt, zAt);
gl.glMatrixMode(GL2.GL_MODELVIEW);
}
public void camDynamic(float xKey, float yKey, float zKey, float xMouse, float yMouse) {If we wanna switch camera while running application we have to switch our position, we can do so with simple:
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45f, 2, 0.1f, 500);
// Forward & back while follow lookat point
xAt += (float) Math.sin(Math.toRadians(xMouse)) * zKey *
// fly up & down follow lookat point
(float) Math.cos(Math.toRadians(yMouse)) +
// Left & right while looking perpendiculary at lookat point
(float) Math.sin(Math.toRadians(xMouse - 90)) * xKey;
zAt -= (float) Math.cos(Math.toRadians(xMouse)) * zKey *
(float) Math.cos(Math.toRadians(yMouse)) +
(float) Math.cos(Math.toRadians(xMouse - 90)) * xKey;
// fly up & down // fly up & down follow lookat point
yAt -= yKey + (float) Math.sin(Math.toRadians(yMouse)) * zKey;
// rotation
xLook = xAt + (float) Math.sin(Math.toRadians(xMouse)) *
(float) Math.cos(Math.toRadians(yMouse));
yLook = yAt - (float) Math.sin(Math.toRadians(yMouse));
zLook = zAt - (float) Math.cos(Math.toRadians(xMouse)) *
(float) Math.cos(Math.toRadians(yMouse));
glu.gluLookAt(xAt, yAt, zAt, xLook, yLook, zLook, 0, 1, 0);
}
public void resetCamera() {
xAt *= -1.0f;
yAt *= -1.0f;
zAt *= -1.0f;
}
Next >>