router.config.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /*
  3. *---------------------------------------------------------------
  4. * Router map configuration
  5. *---------------------------------------------------------------
  6. *
  7. * You can use this configuration to set you default application
  8. * routes.
  9. */
  10. return array(
  11. /*
  12. * Not Found and internal Server Error
  13. */
  14. '#404' => 'Error@404',
  15. '#500' => 'Error@500',
  16. /**
  17. * Plaintext response benchmark
  18. */
  19. 'plaintext' => function()
  20. {
  21. $response = CCResponse::create("Hello, World!", 200);
  22. $response->header("Content-Type", "text/plain; charset=UTF-8");
  23. return $response;
  24. },
  25. /**
  26. * JSON response benchmark
  27. */
  28. 'json' => function()
  29. {
  30. return CCResponse::create( json_encode(
  31. array('message' => 'Hello, World!')
  32. ), 200 )->header( 'Content-Type', 'application/json' );
  33. },
  34. /**
  35. * DB response benchmark
  36. */
  37. 'db' => function()
  38. {
  39. $world = DB::select( 'World' )->find( mt_rand(1, 10000) );
  40. $world->id = intval($world->id);
  41. $world->randomNumber = intval($world->randomNumber);
  42. return CCResponse::create( json_encode( $world), 200 )
  43. ->header( 'Content-Type', 'application/json' );
  44. },
  45. /**
  46. * Qeuries response benchmark
  47. */
  48. 'queries' => function()
  49. {
  50. $queries = CCIn::get( 'queries', 1 );
  51. if ($queries < 1) {
  52. $queries = 1;
  53. }
  54. if ($queries > 500) {
  55. $queries = 500;
  56. }
  57. $worlds = array();
  58. for($i = 0; $i < $queries; ++$i)
  59. {
  60. $world = DB::select( 'World' )->find( mt_rand(1, 10000) );
  61. $world->id = intval($world->id);
  62. $world->randomNumber = intval($world->randomNumber);
  63. $worlds[] = $world;
  64. }
  65. return CCResponse::create( json_encode( $worlds), 200 )
  66. ->header( 'Content-Type', 'application/json' );
  67. },
  68. /**
  69. * Updates response benchmark
  70. */
  71. 'updates' => function()
  72. {
  73. $queries = CCIn::get( 'queries', 1 );
  74. if ($queries < 1) {
  75. $queries = 1;
  76. }
  77. if ($queries > 500) {
  78. $queries = 500;
  79. }
  80. $worlds = array();
  81. for($i = 0; $i < $queries; ++$i)
  82. {
  83. $id = mt_rand(1, 10000);
  84. DB::update( 'World' )
  85. ->set( 'randomNumber', mt_rand(1, 10000) )
  86. ->where( 'id', $id )
  87. ->run();
  88. $world = DB::select( 'World' )->find( $id );
  89. $world->id = intval($world->id);
  90. $world->randomNumber = intval($world->randomNumber);
  91. $worlds[] = $world;
  92. }
  93. return CCResponse::create( json_encode( $worlds), 200 )
  94. ->header( 'Content-Type', 'application/json' );
  95. },
  96. 'fortunes' => 'Bench@fortunes',
  97. );