Skip to content

Instantly share code, notes, and snippets.

@tlevi
Created January 19, 2015 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlevi/4ec40ead97835947ff5d to your computer and use it in GitHub Desktop.
Save tlevi/4ec40ead97835947ff5d to your computer and use it in GitHub Desktop.
accesslib_roledefs_benchmark
<?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";
<?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