Created
January 19, 2015 10:46
-
-
Save tlevi/4ec40ead97835947ff5d to your computer and use it in GitHub Desktop.
accesslib_roledefs_benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('CLI_SCRIPT', true); | |
require_once __DIR__.'/config.php'; | |
$t = microtime(true); | |
$size = 0; | |
for ($i = 1; $i <= 1000; $i++) { | |
$user = $DB->get_record_sql("SELECT * FROM {user} WHERE id = :id", array('id' => $i)); | |
$ad = get_user_accessdata($user->id); | |
$size += strlen(serialize($ad)); | |
} | |
$t = microtime(true) - $t; | |
echo "Time: ".number_format($t, 2)."s\n"; | |
echo "PMU: ".memory_get_peak_usage()."\n"; | |
echo "Accessdata sum: $size\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('CLI_SCRIPT', true); | |
require_once __DIR__.'/config.php'; | |
$n = 200000; | |
$max = round(sqrt($n)); | |
for ($i = 0; $i < $max; $i++) { | |
echo "\r".number_format(100*$i/$max, 0)."%"; | |
$cap = $DB->get_field_sql("SELECT name FROM {capabilities} ORDER BY random() LIMIT 1"); | |
for ($k = 0; $k < $max; $k++) { | |
$id = $DB->get_field_sql("SELECT id FROM {context} WHERE contextlevel >= 50 ORDER BY random() LIMIT 1"); | |
$context = context::instance_by_id($id); | |
assign_capability($cap, CAP_ALLOW, 4, $context, true); | |
assign_capability($cap, CAP_PROHIBIT, 5, $context, true); | |
$context->mark_dirty(); | |
} | |
} | |
echo "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment