From b180cb31b7c57246e05e26ac632ade14b59d424c Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Thu, 4 Apr 2013 14:11:49 +0000
Subject: [PATCH] =?UTF-8?q?Benchmark=20recherche=20avant=20/=20apr=C3=A8s?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

0.auteur
- requete: 1.241854
- resultat: 1.84895
- retour: 1.156744
- total: 4.247548
+ total: 2.449143
1.Millenium
- requete: 0.393574
- resultat: 0.675219
- retour: 0.66293
- total: 1.731723
+ total: 1.728375
2.France
- requete: 0.87455
- resultat: 1.482955
- retour: 1.051353
- total: 3.408858
+ total: 2.354162
3.Livre
- requete: 3.895741
- resultat: 2.919363
- retour: 2.429558
- total: 9.244662
+ total: 3.180693
4.loisirs
- requete: 1.239962
- resultat: 1.172184
- retour: 1.282938
- total: 3.695084
+ total: 8.41166
5.sports
- requete: 3.146724
- resultat: 3.278857
- retour: 1.562699
- total: 7.98828
+ total: 5.520501
6.jardin
- requete: 1.043434
- resultat: 1.561235
- retour: 1.595568
- total: 4.200237
+ total: 3.087021
7.informatique
- requete: 0.444179
- resultat: 0.980564
- retour: 1.069331
- total: 2.494074
+ total: 2.290389
8.univers
- requete: 0.874648
- resultat: 1.673911
- retour: 1.681802
- total: 4.230361
+ total: 2.463609
9.bouteille
- requete: 0.7229
- resultat: 0.843859
- retour: 1.199328
- total: 2.766087
+ total: 2.455177
10.eau
- requete: 0.857304
- resultat: 1.058434
- retour: 1.168076
- total: 3.083814
+ total: 2.857011
11.telephone
- requete: 0.42801
- resultat: 0.989357
- retour: 0.956355
- total: 2.373722
+ total: 1.821091
12.Mac
- requete: 0.576785
- resultat: 0.963315
- retour: 2.037919
- total: 3.578019
+ total: 4.078872
13.Hercule
- requete: 0.421559
- resultat: 1.831345
- retour: 3.212408
- total: 5.465312
+ total: 3.866699
14.Emacs
- requete: 0.69655
- resultat: 0.78371
- retour: 1.469973
- total: 2.950233
+ total: 1.364921
15.Ordinateur
- requete: 0.467888
- resultat: 1.916581
- retour: 2.4459
- total: 4.830369
+ total: 3.858778
16.son
- requete: 0.439505
- resultat: 2.081942
- retour: 1.803424
- total: 4.324871
+ total: 6.204196
17.Millenium
- requete: 2.246785
- resultat: 2.524391
- retour: 1.576251
- total: 6.347427
+ total: 3.286876
== TOTAL OLD: 76.960681
== TOTAL NEW: 61.279174
[lla@snoopix scripts]$

[lla@snoopix scripts]$

[lla@snoopix scripts]$

[lla@snoopix scripts]$

[lla@snoopix scripts]$

[lla@snoopix scripts]$ php test_performance_recherche.php
php test_performance_recherche.php
0.auteur
- requete: 6.54818
- resultat: 2.173249
- total: 8.721429
+ total: 1.450016
1.Millenium
- requete: 0.45366
- resultat: 0.720722
- total: 1.174382
+ total: 0.816225
2.France
- requete: 0.757676
- resultat: 1.284568
- total: 2.042244
+ total: 3.314868
3.Livre
- requete: 1.290288
- resultat: 2.225522
- total: 3.51581
+ total: 1.990504
4.loisirs
- requete: 0.595711
- resultat: 1.243917
- total: 1.839628
+ total: 1.472868
5.sports
- requete: 0.457497
- resultat: 1.217767
- total: 1.675264
+ total: 1.351179
6.jardin
- requete: 0.587545
- resultat: 1.334184
- total: 1.921729
+ total: 1.778264
7.informatique
- requete: 0.431317
- resultat: 1.291357
- total: 1.722674
+ total: 1.325365
8.univers
- requete: 0.409296
- resultat: 1.379941
- total: 1.789237
+ total: 1.499483
9.bouteille
- requete: 0.341038
- resultat: 0.967211
- total: 1.308249
+ total: 1.342272
10.eau
- requete: 0.799039
- resultat: 2.208446
- total: 3.007485
+ total: 1.514647
11.telephone
- requete: 0.733329
- resultat: 1.389585
- total: 2.122914
+ total: 1.134554
12.Mac
- requete: 0.368305
- resultat: 1.204195
- total: 1.5725
+ total: 1.050333
13.Hercule
- requete: 0.331714
- resultat: 0.768907
- total: 1.100621
+ total: 0.866338
14.Emacs
- requete: 0.550099
- resultat: 0.549318
- total: 1.099417
+ total: 0.570752
15.Ordinateur
- requete: 0.380963
- resultat: 1.145829
- total: 1.526792
+ total: 1.44303
16.son
- requete: 0.388003
- resultat: 1.260212
- total: 1.648215
+ total: 1.363374
17.Millenium
- requete: 0.332324
- resultat: 0.742684
- total: 1.075008
+ total: 1.402642
== TOTAL OLD: 38.863598
== TOTAL NEW: 25.686714
---
 scripts/test_performance_recherche.php | 137 +++++++++++++++----------
 1 file changed, 85 insertions(+), 52 deletions(-)

diff --git a/scripts/test_performance_recherche.php b/scripts/test_performance_recherche.php
index 2c6a8a50f92..d9a5260f658 100644
--- a/scripts/test_performance_recherche.php
+++ b/scripts/test_performance_recherche.php
@@ -1,66 +1,99 @@
 <?php
+error_reporting(E_ALL^E_DEPRECATED);
 
 function old_recherche($expression_recherchee){
-$cookie_file = "/tmp/cookie/cookie_1.txt";
-$url_old_recherche = "http://web.afi-sa.net/pergame-enligne.net/recherche/simple";
-$url_new_recherche = "http://web.afi-sa.net/opacce.pergame.net/recherche/simple/expressionRecherche/";    
-$post_fields=array('expressionRecherche'=>urlencode($expression_recherchee));
-//"expressionRecherche=$expression_recherchee";	
-//$item_recherche;
+	$cookie_file = tempnam("/tmp", "cookie");
+	$url_recherche = "http://web.afi-sa.net/pergame-enligne.net/recherche/simple";
+
 
 // OLD recherche Step1 fill cookie
-    $curl_old_step_1 = curl_init($url_old_recherche);
-    
-    curl_setopt($curl_old_step_1,CURLOPT_COOKIESESSION, true);
-    curl_setopt($curl_old_step_1,CURLOPT_COOKIEJAR, $cookie_file);
-    curl_setopt ($curl_old_step_1, CURLOPT_RETURNTRANSFER, true);
-    curl_setopt($curl_old_step_1,CURLOPT_COOKIEFILE, $cookie_file); 
-    curl_setopt($curl_old_step_1,CURLOPT_POSTFIELDS, $post_fields);
-
-    $result_old_step_1 = curl_exec($curl_old_step_1);
-    $temps_step_1 = curl_getinfo($curl_old_step_1,CURLINFO_TOTAL_TIME );
-    echo($temps_step_1);
+	$curl_old_step_1 = curl_init($url_recherche);
+	curl_setopt($curl_old_step_1,CURLOPT_COOKIEJAR, $cookie_file);
+	curl_setopt($curl_old_step_1,CURLOPT_COOKIEFILE, $cookie_file); 
+	curl_setopt($curl_old_step_1, CURLOPT_RETURNTRANSFER, true);
+	curl_setopt($curl_old_step_1,CURLOPT_POSTFIELDS, 'expressionRecherche='.$expression_recherchee);
+	curl_setopt($curl_old_step_1,CURLOPT_POST, true);
+
+	$result_old_step_1 = curl_exec($curl_old_step_1);
+	$temps_step_1 = curl_getinfo($curl_old_step_1,CURLINFO_TOTAL_TIME );
+	curl_close($curl_old_step_1);
 
 // OLD recherche Step2 recherche/simple avec cookie
 
-    $curl_old_step_2 = curl_init($url_old_recherche);
-    curl_setopt($curl_old_step_2,CURLOPT_COOKIEJAR, $cookie_file); 
-
-    $result_old_step_2 = curl_exec($curl_old_step_2);
-    $temps_step_2 = curl_getinfo($curl_old_step_2,CURLINFO_TOTAL_TIME );
-    echo '<br/>';
-    echo($temps_step_1);
-    echo '<br/>';
-    echo($temps_step_2);
-    echo '<br/>';
-    $total_time = $temps_step_1 + $temps_step_2;
-    echo($total_time);
-    
+	$curl_old_step_2 = curl_init($url_recherche);
+	curl_setopt($curl_old_step_2,CURLOPT_COOKIEJAR, $cookie_file);
+	curl_setopt($curl_old_step_2,CURLOPT_COOKIEFILE, $cookie_file); 
+	curl_setopt($curl_old_step_2, CURLOPT_RETURNTRANSFER, true);
+
+	$result_old_step_2 = curl_exec($curl_old_step_2);
+	$temps_step_2 = curl_getinfo($curl_old_step_2,CURLINFO_TOTAL_TIME );
+	curl_close($curl_old_step_2);
+
+	if (false == strpos($result_old_step_2, 'Recherche : '.$expression_recherchee)) {
+		echo "Error\n";
+	}
+
+	echo "- requete: $temps_step_1\n";
+	echo "- resultat: $temps_step_2\n";
+	$total_time = $temps_step_1 + $temps_step_2;
+	echo "- total: $total_time\n";
+	return $total_time;
+}
+
+
+
+function new_recherche($expression_recherchee){
+	$cookie_file = tempnam("/tmp", "cookie");
+	$url_recherche = "http://opacce.pergame.net/opacce.pergame.net/recherche/simple/expressionRecherche/";    
+
+	$curl_old_step_1 = curl_init($url_recherche.$expression_recherchee);
+	curl_setopt($curl_old_step_1,CURLOPT_COOKIEJAR, $cookie_file);
+	curl_setopt($curl_old_step_1,CURLOPT_COOKIEFILE, $cookie_file); 
+	curl_setopt($curl_old_step_1,CURLOPT_RETURNTRANSFER, true);
+
+	$result_old_step_1 = curl_exec($curl_old_step_1);
+	$total_time  = curl_getinfo($curl_old_step_1,CURLINFO_TOTAL_TIME );
+	curl_close($curl_old_step_1);
+
+	if (false == strpos($result_old_step_1, 'Recherche: '.$expression_recherchee)) {
+		echo "Error\n";
+	}
+
+	echo "+ total: $total_time\n";
+	return $total_time;
 }
 
+
 // main
+$recherches = [
+	'auteur',
+	'Millenium',
+	'France',
+	'Livre',
+	'loisirs',
+	'sports',
+	'jardin',
+	'informatique',
+	'univers',
+	'bouteille',
+	'eau',
+	'telephone',
+	'Mac',
+	'Hercule',
+	'Emacs',
+	'Ordinateur',
+	'son',
+	'Millenium'];
+
+$total_old = 0;
+$total_new = 0;
+foreach($recherches as $i => $expression) {
+	echo "$i.$expression\n";
+	$total_old = $total_old + old_recherche($expression);
+	$total_new = $total_new + new_recherche($expression);
+}
 
-$array_item_a_rechercher = [
-    'Millenium',
-    'auteur',
-    'France',
-    'Livre',
-    'loisirs',
-    'sports',
-    'jardin',
-    'informatique',
-    'univers',
-    'bouteille',
-    'eau',
-    'telephone',
-    'Mac',
-    'Hercule',
-    'Emacs',
-    'Ordinateur',
-    'son',
-    'Millenium'];
-
-
-old_recherche('Millenium');
+echo "== TOTAL OLD: $total_old\n";
+echo "== TOTAL NEW: $total_new\n";
 
 ?>
\ No newline at end of file
-- 
GitLab