(2% N) ou (N & 1) pour les cotes et Evens

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Inscription: Fév 10, 2004
  • Messages: 13458
  • Loc: Florida
  • Status: Offline

Message Juin 29th, 2010, 2:53 pm

Les résultats de cet essai n'a pas peu de la manière que je pensais qu'ils le feraient. Theyre étroite, mais on est toujours contre l'autre pour moi.

PHP Code: [ Select ]
<pre><?php
 
$total_1 = 0;
$total_2 = 0;
$total_3 = 0;
$i = 0;
$j = 0;
$k = 0;
$start_1 = 0;
$start_2 = 0;
$start_3 = 0;
$end_1 = 0;
$end_2 = 0;
$end_3 = 0;
 
$start_1 = microtime(true);
for($i = 0; $i < 1000000; $i++)
{
   if ($i % 2)
   {
      $total_1++;
   }
}
$end_1 = microtime(true);
 
$start_2= microtime(true);
for($j = 0; $j < 1000000; $j++)
{
   if ($j & 1)
   {
      $total_2++;
   }
}
$end_2 = microtime(true);
 
$start_3 = microtime(true);
for($k = 0; $k < 1000000; $k++)
{
   if ($k << 31)
   {
      $total_3++;
   }
}
$end_3 = microtime(true);
 
echo '$i % 2: ', ($end_1 - $start_1), " | total: $total_1\n";
echo '$j & 1: ', ($end_2 - $start_2), " | total: $total_2\n";
echo '$k << 31: ', ($end_3 - $start_3), " | total: $total_3\n";
 
?></pre>
  1. <pre><?php
  2.  
  3. $total_1 = 0;
  4. $total_2 = 0;
  5. $total_3 = 0;
  6. $i = 0;
  7. $j = 0;
  8. $k = 0;
  9. $start_1 = 0;
  10. $start_2 = 0;
  11. $start_3 = 0;
  12. $end_1 = 0;
  13. $end_2 = 0;
  14. $end_3 = 0;
  15.  
  16. $start_1 = microtime(true);
  17. for($i = 0; $i < 1000000; $i++)
  18. {
  19.    if ($i % 2)
  20.    {
  21.       $total_1++;
  22.    }
  23. }
  24. $end_1 = microtime(true);
  25.  
  26. $start_2= microtime(true);
  27. for($j = 0; $j < 1000000; $j++)
  28. {
  29.    if ($j & 1)
  30.    {
  31.       $total_2++;
  32.    }
  33. }
  34. $end_2 = microtime(true);
  35.  
  36. $start_3 = microtime(true);
  37. for($k = 0; $k < 1000000; $k++)
  38. {
  39.    if ($k << 31)
  40.    {
  41.       $total_3++;
  42.    }
  43. }
  44. $end_3 = microtime(true);
  45.  
  46. echo '$i % 2: ', ($end_1 - $start_1), " | total: $total_1\n";
  47. echo '$j & 1: ', ($end_2 - $start_2), " | total: $total_2\n";
  48. echo '$k << 31: ', ($end_3 - $start_3), " | total: $total_3\n";
  49.  
  50. ?></pre>
Strong with this one, the sudo is.
  • Anonymous
  • Bot
  • No Avatar
  • Inscription: 25 Feb 2008
  • Messages: ?
  • Loc: Ozzuland
  • Status: Online

Message Juin 29th, 2010, 2:53 pm

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Inscription: Fév 10, 2004
  • Messages: 13458
  • Loc: Florida
  • Status: Offline

Message Juin 29th, 2010, 3:12 pm

Par curiosité, j'ai essayé avec décalage de bits . Décalage de bits fonctionne à peu près à égalité avec modulo , Ils ont tous deux battu eachother environ la moitié du temps. Le niveau du bit ET est plus lent que les deux consistiently modulo et décalage de bits.

J'ai mis à jour de la morue dans mon message original.
Strong with this one, the sudo is.
  • righteous_trespasser
  • Scuffle
  • Genius
  • Avatar de l’utilisateur
  • Inscription: Mar 12, 2007
  • Messages: 6228
  • Loc: South-Africa
  • Status: Offline

Message Juin 30th, 2010, 5:27 am

on my wamp the script a écrit:
$ I% 2: 0,27078700065613 | Total: 500000
j $ & 1: 0,24281907081604 | Total: 500000
k $ <<31: 0,25018215179443 | Total: 500000
Let's leave all our *plum* where it is and go live in the jungle ...
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Inscription: Fév 10, 2004
  • Messages: 13458
  • Loc: Florida
  • Status: Offline

Message Juin 30th, 2010, 8:24 am

Ma première course cet après-midi.

Code: [ Select ]
$i % 2: 0.2589 | total: 500000
$j & 1: 0.2662 | total: 500000
$k << 31: 0.2493 | total: 500000
  1. $i % 2: 0.2589 | total: 500000
  2. $j & 1: 0.2662 | total: 500000
  3. $k << 31: 0.2493 | total: 500000


Après quelques courses il retourna à la recherche comme hier bien.
Code: [ Select ]
$i % 2: 0.2567 | total: 500000
$j & 1: 0.272 | total: 500000
$k << 31: 0.25 | total: 500000
  1. $i % 2: 0.2567 | total: 500000
  2. $j & 1: 0.272 | total: 500000
  3. $k << 31: 0.25 | total: 500000


Je trouve intéressant que pas une seule fois je n'ai eu le bit-sage et battu l'une des deux autres. Je suppose que c'est un bonne chose que chacun d'eux, prendre à droite dans le même laps de temps.

(Php.ini: précision = 4)
Version PHP 5.2.6-3ubuntu4.5
Linux 2.6.28 sr1123wm-19-server #61-Ubuntu SMP jeu. 27 mai 2010 00:25:35 UTC i686
Strong with this one, the sudo is.
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • Avatar de l’utilisateur
  • Inscription: Mai 22, 2004
  • Messages: 3415
  • Loc: Richland, WA
  • Status: Offline

Message Juin 30th, 2010, 11:00 am

J'ai juste couru le code ci-dessus:
Terminal:
Code: [ Select ]
$i % 2: 0.15300297737122 | total: 500000
$j & 1: 0.13465905189514 | total: 500000
$k << 31: 0.15124988555908 | total: 999999
  1. $i % 2: 0.15300297737122 | total: 500000
  2. $j & 1: 0.13465905189514 | total: 500000
  3. $k << 31: 0.15124988555908 | total: 999999

Apache:
Code: [ Select ]
$i % 2: 0.16692686080933 | total: 500000
$j & 1: 0.14606189727783 | total: 500000
$k << 31: 0.16066813468933 | total: 999999
  1. $i % 2: 0.16692686080933 | total: 500000
  2. $j & 1: 0.14606189727783 | total: 500000
  3. $k << 31: 0.16066813468933 | total: 999999
#define NULL (::rand() % 2)
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Inscription: Fév 10, 2004
  • Messages: 13458
  • Loc: Florida
  • Status: Offline

Message Juin 30th, 2010, 11:50 am

Je me demande pourquoi tu as 999999 pour cette dernière, frauduleux. :scratchhead: Ma meilleure supposition est que vous utilisez un processeur 64-bits et 31 bits déplacer encore laisse toujours un peu à TRUE dans les 33 bits résultant.
Strong with this one, the sudo is.
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • Avatar de l’utilisateur
  • Inscription: Mai 22, 2004
  • Messages: 3415
  • Loc: Richland, WA
  • Status: Offline

Message Juin 30th, 2010, 12:27 pm

Ya

Code: [ Select ]
me@server: uname -m
x86_64
  1. me@server: uname -m
  2. x86_64
#define NULL (::rand() % 2)

Afficher de l'information

  • Total des messages de ce sujet: 7 messages
  • Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 107 invités
  • Vous ne pouvez pas poster de nouveaux sujets
  • Vous ne pouvez pas répondre aux sujets
  • Vous ne pouvez pas éditer vos messages
  • Vous ne pouvez pas supprimer vos messages
  • Vous ne pouvez pas joindre des fichiers
 
 

© 2011 Unmelted, LLC. Ozzu® est une marque déposée de Unmelted, LLC