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
var TestModule = { | |
x: function(a){ | |
return a * a; | |
}, | |
y: {p:2, q:5} | |
}; | |
print(TestModule.x(5)); // 25 | |
print(TestModule.y.p); // 2 |
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
function count() { | |
var i = 0; | |
return function() { | |
return ++i; | |
} | |
} | |
var x = count(); | |
x(); // 1 | |
x(); // 2 |
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
// 修正する箇所 (この例ではすでに記述) | |
$ egrep -n 'query_cache_type|query_cache_size' /etc/my.cnf | |
697:query_cache_type = 0 | |
705:query_cache_size = 256M | |
// 書き換える前にバックアップを取得(my.cnf.yyyymmddが作成される) | |
$ sudo cp -p /etc/my.cnf{,.`date +%Y%m%d`} | |
// 修正する | |
$ sudo vim /etc/my.cnf |
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
// 並列5でそれぞれ10回selectさせる | |
$ mysqlslap -u user -p --delimiter=";" --query="SELECT hoge FROM table WHERE id = 0;" --number-of-queries=50 --concurrency=5 | |
Benchmark | |
Average number of seconds to run all queries: 3.631 seconds | |
Minimum number of seconds to run all queries: 3.631 seconds | |
Maximum number of seconds to run all queries: 3.631 seconds | |
Number of clients running queries: 5 | |
Average number of queries per client: 10 | |
// クエリキャッシュ設定後 |
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
// 変更前 | |
mysql > SELECT hoge FROM table WHERE id = 0; | |
-- 出力は省略 -- | |
3 rows in set (0.34 sec) | |
// 変更 (検証するだけなのにmy.cnf書き換えてmysql restartするのは面倒なのでオンラインで実行する) | |
mysql > SET SESSION query_cache_type = 'ON'; | |
mysql > SET GLOBAL query_cache_type = 'ON'; | |
mysql > SET GLOBAL query_cache_size = 16777216; |
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
// 値がYESならばキャッシュすることになっている | |
mysql > show variables like 'have_query_cache'; | |
+------------------+-------+ | |
| Variable_name | Value | | |
+------------------+-------+ | |
| have_query_cache | YES | | |
+------------------+-------+ | |
1 row in set (0.04 sec) | |
// キャッシュについてのステータス |
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
var x = {}; | |
print (x.y); // undefined | |
print (x.y.z); // Exception: TypeError: 'undefined' is not an object (evaluating 'x.y.z') | |
// x.yが偽だった左項を評価するだけ | |
print(x.y && x.y.z); // undefined | |
var x = {y:{z:1}} | |
print (x.y); // [object Object] | |
print (x.y.z); // 1 | |
// x.yが真だったため右項を評価する |
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
var x = {}; | |
print(x.y); // undefined | |
// undefined値のプロパティにアクセスするとTypeErrorになる | |
print(x.y.z); //Exception: TypeError: 'undefined' is not an object (evaluating 'x.y.z') |
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
// ||の左項をブーリアン型に変換して真になるなら左項を評価する | |
print(1 || 3); // 1 | |
print(3 || 0); // 3 | |
// 左項が真の場合に右項は評価されない | |
var x = 0; | |
print(3 || (x = 1)); // 3 | |
print(x); // 0 | |
// 左項が偽の場合に右項が評価される |
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
function test(a_val) { | |
var a = a_val || 7; | |
print(a); | |
} | |
test(); // 7 | |
test(3); // 3 |