Skip to content

Instantly share code, notes, and snippets.

@sandacn
Last active December 17, 2015 18:19
Show Gist options
  • Save sandacn/5652340 to your computer and use it in GitHub Desktop.
Save sandacn/5652340 to your computer and use it in GitHub Desktop.
<?php
ini_set('xdebug.trace_format', '1');
class MyPhotoBO {
public static $SPEC_GIANT = "giant";
public static $SPEC_BIG = "big";
public static $SPEC_MIDDLE = "middle";
public static $SPEC_MIDDLE_BIG = "middlebig";
public static $SPEC_SQUARE_200 = "middlesquare";
public static $SPEC_SQUARE_100 = "smallsquare";
public static $SPEC_FIT_100 = "smallfit";
public static $SPEC_MIDDLE_PRODUCT = "middleproduct";
public static $SPEC_SQUARE_49 = "smallheadsquare";
public static $SPEC_NEW_BIG = "newbig";
public static $SPEC_FIT_210 = "fit210";
public static $MR_SPEC_BIG = 'mr_spec_big';
public static $MR_SPEC_MIDDLE = 'mr_spec_middle';
public static $MR_SPEC_SQUARE_200 = 'mr_square_200';
public static $MR_SPEC_SQUARE_100 = 'mr_square_100';
public static $MR_SPEC_FIT_100 = 'mr_fit_100';
public static $MR_SPEC_NEW_BIG = 'mr_spec_new_big';
public static function getSpecMap () {
return array (
self::$SPEC_BIG => array(0, 1280, 1280, '_b', 80, 1, 0),
self::$SPEC_MIDDLE_BIG => array(0, 640, 640, '_mb', 90, 2, 0),
self::$SPEC_MIDDLE => array(0, 480, 480, '_m', 90, 2, 0),
self::$SPEC_SQUARE_200 => array(1, 200, 200, '_sm', 95, 3, 1),
self::$SPEC_SQUARE_100 => array(1, 100, 100, '_ss', 100, 4, 1),
self::$SPEC_FIT_100 => array(0, 100, 100, '_sf', 100, 2, 1),
self::$SPEC_SQUARE_49 => array(1, 49, 49, '_hs', 100, 5, 1),
self::$SPEC_NEW_BIG => array(0, 960, 960, '_nb', 90, 2, 0),
);
}
}
class ConstMyPhotoBO {
const SPEC_GIANT = "giant";
const SPEC_BIG = "big";
const SPEC_MIDDLE = "middle";
const SPEC_MIDDLE_BIG = "middlebig";
const SPEC_SQUARE_200 = "middlesquare";
const SPEC_SQUARE_100 = "smallsquare";
const SPEC_FIT_100 = "smallfit";
const SPEC_MIDDLE_PRODUCT = "middleproduct";
const SPEC_SQUARE_49 = "smallheadsquare";
const SPEC_NEW_BIG = "newbig";
const SPEC_FIT_210 = "fit210";
const MR_SPEC_BIG = 'mr_spec_big';
const MR_SPEC_MIDDLE = 'mr_spec_middle';
const MR_SPEC_SQUARE_200 = 'mr_square_200';
const MR_SPEC_SQUARE_100 = 'mr_square_100';
const MR_SPEC_FIT_100 = 'mr_fit_100';
const MR_SPEC_NEW_BIG = 'mr_spec_new_big';
public static $spec_map = array(
self::SPEC_BIG => array(0, 1280, 1280, '_b', 80, 1, 0),
self::SPEC_MIDDLE_BIG => array(0, 640, 640, '_mb', 90, 2, 0),
self::SPEC_MIDDLE => array(0, 480, 480, '_m', 90, 2, 0),
self::SPEC_SQUARE_200 => array(1, 200, 200, '_sm', 95, 3, 1),
self::SPEC_SQUARE_100 => array(1, 100, 100, '_ss', 100, 4, 1),
self::SPEC_FIT_100 => array(0, 100, 100, '_sf', 100, 2, 1),
self::SPEC_SQUARE_49 => array(1, 49, 49, '_hs', 100, 5, 1),
self::SPEC_NEW_BIG => array(0, 960, 960, '_nb', 90, 2, 0),
);
public static function getSpecMap () {
return self::$spec_map;
}
}
$max_time = 100000;
for ($i = 0; $i < $max_time; $i++) {
$spec_map = MyPhotoBO::getSpecMap();
$const_spec_map = ConstMyPhotoBO::getSpecMap();
}
@sandacn
Copy link
Author

sandacn commented May 26, 2013

php -d xdebug.auto_trace=1 gc_test.php 可以发现ConstMyPhotoBO的getSpecMap的内存消耗极少,基本上是没有,但是MyPhotoBO::getSpecMap(),消耗极大,每次都会生成新的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment