$allowed_pollutants = array("pm10", "no2", "pm2.5", "co");
$output = "";
foreach ($pollutants as $pollutant) {
    // validity checking
    if (!in_array($pollutant, $allowed_pollutants)) {
        $error = true;
    }
    if ($error) {
        break;
    }
    // validity checking
    for ($i = 0; $i < count($latitudes); $i++) {
        $datetimes[$i] = date('Y-m-d H:i:s', strtotime($datetimes[$i]));
        if (abs($latitudes[$i]) > 90 || abs($longitudes[$i]) > 180) {
            $error = true;
        }
        if (strtotime($datetimes[$i]) < strtotime('2010-01-01')) {
            $error = true;
        }
        if ($error) {
            break;
        }
    }
    if (!$error) {
        $levels = model_pollutant_points_for_locations_and_times($latitudes, $longitudes, $datetimes, $pollutant);
    }
    $output .= "{$pollutant}=" . implode(",", $levels) . "\n";
}
if (!$error) {
    echo $output;
}
    $t1 = microtime(true);
    for ($i = 0; $i < count($latitudes); $i++) {
        $datetimes[$i] = date('Y-m-d H:i:s', strtotime($datetimes[$i]));
        $r = model_pollutant_point($latitudes[$i], $longitudes[$i], 100, $datetimes[$i], 200, "pm10");
        array_push($levels_slow, $r);
    }
    $t2 = microtime(true);
    $oldtime = $t2 - $t1;
}
$time_window = 15 * 60;
// 15 minutes
$loc_window = 10;
// km
$t1 = microtime(true);
//$levels_fast = model_pollutant_points_for_locations_and_times_custom_window($latitudes, $longitudes, $datetimes, 'co', $time_window, $loc_window);
$levels_fast = model_pollutant_points_for_locations_and_times($latitudes, $longitudes, $datetimes, 'no2');
$t2 = microtime(true);
$newtime = $t2 - $t1;
/*
	$time_window = 30*60; // 30 minutes
	$loc_window = 100; // km
	$levels_fast1 = model_pollutant_points_for_locations_and_times_custom_window($latitudes, $longitudes, $datetimes, 'pm10', $time_window, $loc_window);
	
	$time_window = 60*60; // 60 minutes
	$loc_window = 500; // km
	$levels_fast2 = model_pollutant_points_for_locations_and_times_custom_window($latitudes, $longitudes, $datetimes, 'pm10', $time_window, $loc_window);
*/
echo "Count: " . count($latitudes);
echo "<br>\n";
echo "Old way took {$oldtime} seconds (" . $oldtime / count($latitudes) . " seconds per point";
echo "<br>\n";