#foreachloop
Explore tagged Tumblr posts
simplifyyourday · 1 year ago
Text
🚀 Unraveling the Magic of C#'s foreach Loop! 🔄✚
Ever felt lost in the complexity of looping through elements in C#? 🀯 Fear not! Our latest blog post, "Understanding the foreach Loop," breaks it down into bite-sized, easy-to-grasp pieces. 🧠💡
🔍 Dive into the inner workings of the foreach loop, demystified with straightforward explanations and crystal-clear code examples. 🖥👚‍💻
🚀 Why Should You Care?
- Boost your code readability 📚
- Wave goodbye to off-by-one errors 🚫🕰
- Write cleaner, bug-resistant code 🐜🔍
Ready to simplify your coding journey?
🚀 Click here 👉 [Unlock the Secrets of foreach](Why Does Collections In C# Does Not Implement IEnumerator? | Internals Of 'foreach' Loop) and level up your C# game! 🚀🔗
#CodingMadeEasy #ForEachLoop #CSharpMagic ✹
0 notes
pradtutorials · 5 years ago
Link
C# Foreach Loop with Examples
0 notes
troposal-blog · 5 years ago
Photo
Tumblr media
PHP Loop: For, While, Do While Foreach https://www.troposal.com/php-loop/ #Troposal #PHP #ForLoop #WhileLoop #DoWhileLoop #ForeachLoop #WebDevelopment #Website https://www.instagram.com/p/B_SBSpvnwaM/?igshid=1km6hbesmdkui
0 notes
keysmashstudios · 6 years ago
Photo
Tumblr media
Today, we are showing off how #foreachloop works! Important for iterating through lists, arrays, and other collections! What other #programming knowledge can we teach you? Let us know! https://www.instagram.com/keysmashstudios/p/BwYPuFqlTk8/?utm_source=ig_tumblr_share&igshid=od2k8qvqrdt9
0 notes
moonmurph-gamedev · 7 years ago
Text
Controls Experimentation
Character Possession
We looked into spawning new characters and possessing them. This can be used to spawn any type of actor such as items or enemies but we’re using a character with a skeletal mesh and so we’re able to take control of them.
I placed a box trigger (made visible for testing purposes) and created an BeginOverlap event for it. 
Tumblr media
I then was able use the SpawnActor node and select the character from the drop down list. The “GetActorLocation” finds the target points location in the viewport and sets that as the spawn point for this new character. You can also use either a delay or a retriggerable delay so the DoOnce resets. This is in place so the player can’t continuously spam new characters and flood the level with the old ones. If you for some reason want the player to be able to do this you can simply remove the DoOnce. The delay can also be placed at different parts of the code for example you can have the player needing to stand in the trigger for a certain amount of time before the possession or have it instant like I am.
Tumblr media
Here you can see the old character is still running in place at the box trigger. This will remain here forever until told otherwise. For whatever purposes in your game you might want the character to do a different animation such as idle if you want to repossess this character later on. If however you’re finished with the old character and no longer need it is better to destroy it.
Collisions
Tumblr media
Here’s my blueprint for destroying the old actor. I simply added the destroy actor node right a the moment of the overlap. This is a much simpler way of doing it in my opinion than trying to make every actor overlapping the box trigger to get destroyed. That method could also cause issues as later in the game you might hit the trigger and get deleted by accident.
Tumblr media Tumblr media
I also added a DoOnce so this happens once and never again. I also set the DestoryActor’s target as “Get Player Character” then added “cast to actor” so only the player character activates the trigger box. This is because I only want the player character to be destroyed not every actor that might accidentally trigger the box.
Tumblr media
You can also change how box triggers (and other triggers) work. There are different collision presets which can be used for different purposes. For example “OverlapAllDynamic” will only trigger an overlap when dynamic actors hit the trigger such as projectiles or other moving actors.
Static actors wont trigger the overlap and so they’re safe to use inside the trigger space. Dynamic collision triggers are taxing on the game however as they’re constantly keeping track of all these dynamic actors.
Different collision presets might be needed for different moments in your game. The majority of issues seen in video games are collision problems so when building a game you always need to be aware of what collision you’re working on. Depending on any in game sequences, boss fights or character power ups/attacks might require different collision presets to work properly. Being aware of you’re collision and how it relates to your game will help you loads when coming across issues with your actors. It’s easy to see how complex your blueprint can get especially when needing to change collision presets or actor tags in game. 
Another collision test I did was seeing if a true/false branch could identify if the correct type of actor had entered the trigger. I was having issues as my character was not already placed in the game and instead spawned at the player network. I tried referencing back to “MyNewCharacter” but it was not working so instead this new blueprint which makes use of the “Get all Actors of Class” and “ForEachLoop” has fixed my issue!
Tumblr media
Adding Controls
By going into project settings I’m able to add action mappings such as controls for the character. I began experimenting with a Dash. I made it so the character has a short boost of speed. I also made it so a ghost is left behind of the character and vanished after a short while. 
Tumblr media Tumblr media
Once I’ve narrowed down exactly what kind of attacks and controls I want I’ll begin using the action mappings to place my control layout ingame. I’ll also begin looking into tutorials for creating additional movement such as double jumps, wall climbing and crouch!
0 notes
sdnproject · 8 years ago
Text
JavaScriptのArray関係いろいろ
プログラム関係で必ずず蚀っお䜿うものず蚀えば配列Arrayですね。 JavaScriptの配列はいろいろ面癜いややこしいずも蚀う動䜜をするので改めお自分甚のメモずしおもたずめおおきたす。
Array.length
JavaScriptの配列の長さ芁玠数を知りたいずきに䜿うのはみなさんおなじみ Array.length ですが、この length の挙動に぀いお意倖ず知らない人もいるので改めおおさらいしおみたす。
Array.length は正確には芁玠数ではない
そうなのヌ
以䞋のサンプルを芋おもらえるずどういう事だか理解できるかもしれたせん。
JavaScript
var words = ['すっごヌい', 'たヌのしヌ']; // 初ᅵᅵᅵ状態 console.log(words.length); // 2 // 代入する words[2] = 'たべないよヌ'; console.log(words.length); // 3 // Array.prototype.push を䜿う words.push('倜行性だからねっ'); console.log(words.length); // 4 console.log(words); // ["すっごヌい", "たヌのしヌ", "たべないよヌ", "倜行性だからねっ"] // 倧きなむンデックスに代入しおみる words[100] = '倧䞈倫、倜行性だからっ'; // length は 5 ではない console.log(words.length); // 101 // 配列がどうなっおいるのか芋おみる console.dir(words); /* Array[101] 0: "すっごヌい" 1: "たヌのしヌ" 2: "たべないよヌ" 3: "倜行性だからねっ" 100: "倧䞈倫、倜行性だからっ" length: 101 */
words[4] 〜 words[99] がないのに words.length は 101 になっおたす。 この結果からわかるように、意図的に操䜜しなければ Array.length は最倧のむンデックスの数にプラス1した数倀であり、「芁玠が101個ある配列」ずしお認識されおいたす。 そしお、words[4] 〜 words[99] は実質 undefined が入っおいるのずほが同じずいう解釈ができたす。なぜ「ほが」なのかに぀いおは埌ほど觊れたす
Array.length の倀の倉曎
ご存知のように、Array.length は読み取り専甚プロパティではなく倀を倉曎するこずができたす。 倉曎した時の動䜜はどうなっおいるのでしょうか。
JavaScript
var words = ['すっごヌい', 'たヌのしヌ', 'たべないよヌ']; // 初期状態 console.log(words.length); // 3 // 珟圚の長さよりも小さい倀に倉曎する words.length = 2; console.log(words); // ["すっごヌい", "たヌのしヌ"] // 珟圚の長さよりも倧きい倀に倉曎する words.length = 10; console.log(words); // ["すっごヌい", "たヌのしヌ"] // pushしおみる words.push('倜行性だからねっ'); console.log(words.length); // 11 console.log(words); /* Array[101] 0: "すっごヌい" 1: "たヌのしヌ" 10: "たべないよヌ" length: 11 */
words.length = 2; にした時は予想通りの動䜜になりたしたが、words.length = 10; にしおも芋た目的には倉わりたせん。 しかし length の倀は違うので、この配列は「芁玠が10個ある配列」ずいう扱いになっおいたす。 なので、push した時にむンデックスが 10 から始たるわけです。
動䜜を暡倣しおみる
よく考えるず䞍思議な動䜜をする Array.length ですが、ほが同じ動䜜を暡倣しおみるずこんな感じでしょうか。自信ない
JavaScript
// 今はもうあたり䜿われない new Array() みたいに䜿える function fakeArray() { // new ぀け忘れたら駄目 if (!(this instanceof fakeArray)) { throw new TypeError('Constructor cannot be called as a function'); } var i = 0; // 匕数があるなら入れおおく for (; i < arguments.length; i++) { this[i] = arguments[i]; } // length を定矩する Object.defineProperty(this, 'length', (function () { // 内郚で持぀ length 倀 var lengthTemp = i; return { // ゲッタヌの定矩 get: function () { // 珟圚の length より倧きい堎合 if (this.hasOwnProperty(lengthTemp)) { var maxIndex = lengthTemp - 1; // 最倧のむンデックスを取埗する for (var index in this) { if (this.hasOwnProperty(index) && maxIndex < parseInt(index, 10)) { maxIndex = parseInt(index, 10); } } lengthTemp = maxIndex + 1; } return lengthTemp; }, // セッタヌの定矩 set: function (length) { length = parseInt(length, 10); if (isNaN(length)) { throw new RangeError('Invalid value'); } // 珟圚の length よりも小さい倀の堎合、䜙蚈な芁玠を削陀する if (length < lengthTemp) { for (var index in this) { if (this.hasOwnProperty(index) && length - 1 < parseInt(index, 10)) { delete this[index]; } } } lengthTemp = length; }, }; })()); } fakeArray.prototype = { constructor: fakeArray, // 配列っぜく振る舞うための操䜜 push: Array.prototype.push, sort: Array.prototype.sort, splice: Array.prototype.splice, }; // 配列もどきの生成 var words = new fakeArray('すっごヌい', 'たヌのしヌ'); // 初期状態 console.log(words.length); // 2 // 代入する words[2] = 'たべないよヌ'; console.log(words.length); // 3 // push を䜿う words.push('倜行性だからねっ'); console.log(words.length); // 4 console.log(words); // ["すっごヌい", "たヌのしヌ", "たべないよヌ", "倜行性だからねっ"] // 珟圚の長さよりも小さい倀に倉曎する words.length = 2; console.log(words); // ["すっごヌい", "たヌのしヌ"] // 珟圚の長さよりも倧きい倀に倉曎する words.length = 10; console.log(words); // ["すっごヌい", "たヌのしヌ"] // もう䞀床pushしおみる words.push('倜行性だからねっ'); console.log(words.length); // 11 console.log(words); /* fakeArray[101] 0: "すっごヌい" 1: "たヌのしヌ" 10: "たべないよヌ" length: 11 */
ゲッタヌずセッタヌを䜿うこずでほが配列っぜい動きができたした。 Array.length は芋た目の割に耇雑ですね。なんかむずかしヌ
Array.prototype.forEach ず for ず for...of
配列をルヌプさせる方法ずいえば、普通の for を䜿いたすが、Array.prototype.forEach もありたすね。 そしお ECMAScript 2015 (ES6) から䜿えるむテラブルオブゞェクトのルヌプ構文 for...of が登堎したした。
JavaScript
var words = ['すっごヌい', 'たヌのしヌ', 'たべないよヌ', '倜行性だからねっ'], length = words.length; /* 普通の for */ for (var i = 0; i < length; i++) { console.log(words[i]); } /* Array.prototype.forEach */ words.forEach(function (word) { console.log(word); }); /* for...of */ for (var word of words) { console.log(word); } /* 党郚同じ結ᅵᅵᅵ */ // "すっごヌい" // "たヌのしヌ" // "たべないよヌ" // "倜行性だからねっ"
そもそもの違い
普通の for は、ただ単に条件が false になるたでルヌプを行う構文です。配列ずは盎接関係ない構文ですが、それを配列に利甚しおいる蚳ですね。 Array.prototype.forEach は、芋おわかるように Array.prototype のメ゜ッドなので、完党に配列専甚のメ゜ッドである事がわかりたす。 for...of は、配列だけではなく「むテラブルオブゞェクト」ずいうオブゞェクトであれば䜿甚できるルヌプ構文です。むテラブルオブゞェクトに぀いおはここでは詳しく説明したせん。
凊理的な面でいくず、for ず for...of はルヌプを抜け出す break がありたすが、Array.prototype.forEach にはありたせん。関数実行型なので
JavaScript
var words = ['すっごヌい', 'たヌのしヌ', 'たべないよヌ', '倜行性だからねっ'], breakWord = 'たべないよヌ', length = words.length; /* 普通の for */ for (var i = 0; i < length; i++) { if (words[i] === breakWord) { break; } console.log(words[i]); } // "すっごヌい" // "たヌのしヌ" /* Array.prototype.forEach */ words.forEach(function (word) { if (word === breakWord) { break; } console.log(word); }); // SyntaxError: Illegal break statement // 䞀応 if文 で䌌たような結果にできるが、 // 無駄なルヌプたで実行されおしたう var flag = true; words.forEach(function (word) { if (flag) { if (word !== breakWord) { console.log(word); } else { flag = false; } } }); // "すっごヌい" // "たヌのしヌ" /* for...of */ for (var word of words) { if (word === breakWord) { break; } console.log(word); } // "すっごヌい" // "たヌのしヌ"
jQuery の $.each() は return false; ずする事で break ず同じ事ができたすが、Array.prototype.forEach は凊理は止たりたせん。
他にも、珟圚凊理䞭の文を䞭断しお次のルヌプ凊理を行う continue がありたすが、これは Array.prototype.forEach では return で代甚できたす。
JavaScript
var words = ['すっごヌい', 'たヌのしヌ', 'たべないよヌ', '倜行性だからねっ'], ignoreWord = 'たべないよヌ', length = words.length; /* 普通の for */ for (var i = 0; i < length; i++) { if (words[i] === ignoreWord) { continue; } console.log(words[i]); } // "すっごヌい" // "たヌのしヌ" // "倜行性だからねっ" /* Array.prototype.forEach */ words.forEach(function (word) { if (word === ignoreWord) { return; } console.log(word); }); // "すっごヌい" // "たヌのしヌ" // "倜行性だからねっ" /* for...of */ for (var word of words) { if (word === ignoreWord) { continue; } console.log(word); } // "すっごヌい" // "たヌのしヌ" // "倜行性だからねっ"
凊理速床
さお、どれが䞀番凊理が早いのᅵᅵしょう。10000回ルヌプさせお蚈枬しおみたす。
JavaScript
// 10000個芁玠がある配列を䜜る var testArray = []; for (var i = 0; i < 10000; i++) { testArray[i] = i; } function forLoop() { var length = testArray.length, sum = 0; console.time('for'); for (var i = 0; i < length; i++) { sum += testArray[i]; } console.timeEnd('for'); } function forEachLoop() { var sum = 0; console.time('forEach'); testArray.forEach(function (value) { sum += value; }); console.timeEnd('forEach'); } function forOfLoop() { var sum = 0; console.time('for...of'); for (var value of testArray) { sum += value; } console.timeEnd('for...of'); }
forLoop() ず forEachLoop() ず forOfLoop() をそれぞれ5回実行しおみたした。 バヌゞョンやPC等の環境にも巊右されるのであくたで参考倀です
Node.js (v7.5.0) で実行
1回目 2回目 3回目 4回目 5回目 平均 forLoop() 0.029ms 0.029ms 0.026ms 0.033ms 0.027ms 0.029ms forEachLoop() 0.210ms 0.235ms 0.236ms 0.235ms 0.233ms 0.230ms forOfLoop() 0.331ms 0.367ms 0.282ms 0.368ms 0.328ms 0.335ms
Google Chrome 56 のデベロッパヌツヌルで実行
1回目 2回目 3回目 4回目 5回目 平均 forLoop() 0.029ms 0.024ms 0.026ms 0.028ms 0.029ms 0.027ms forEachLoop() 0.198ms 0.224ms 0.198ms 0.198ms 0.233ms 0.210ms forOfLoop() 0.199ms 0.200ms 0.254ms 0.229ms 0.178ms 0.212ms
さすが、普通の for は早いですね。配列関係なしにルヌプを行うのが匷いのでしょうね。 Node.js では䞀番遅いのは for...of ですが、Chromeでは Array.prototype.forEach ず for...of がほが同じです。
Array.prototype.forEach は、毎回関数を実行しおいる事ずネむティブコヌド内で様々な刀定を行なっおいるので少し凊理に時間がかかるようです。 MDNの Array.prototype.forEach() - JavaScript | MDN の互換性の項目を芋るず、こういった凊理が行われおいるのがわかりたす。なるほどヌ
for...of は、䞀芋普通の for 構文に䌌おいたすが、むテラブルオブゞェクトを反埩するための関数実行を簡略した蚘述みたいなものなので、これも内郚で関数実行が行われおいる関係で少し時間がかかるようです。
配列での undefined
結構ややこしいのが、undefined です。この扱いは結構厄介です。配列だけじゃなくおオブゞェクト党䜓に蚀えるんですけどね
「芁玠が未定矩」ず「倀が未定矩」
undefined はその名の通り「未定矩」ずいう意味ですが、以䞋のような堎合は䜕が違っおくるのでしょう。
JavaScript
/* むンデックスを飛ばしお配列に入れおみる */ var a = ['いらっしゃぁい']; a[2] = 'ゆっぐりしおいっおぇ'; console.log(a); /* Array[101] 0: "いらっしゃぁい" 2: "ゆっぐりしおいっおぇ" length: 3 */ // 芁玠が未定矩なので undefined console.log(a[1]); // undefined // for でルヌプしおみるず、未定矩関係なく凊理する for (var i = 0; i < 3; i++) { console.log(a[i]); } // "いらっしゃぁい" // undefined // "ゆっぐりしおいっおぇ" // for...of でルヌプしおみるず、for ず同じ結果 for (var word of a) { console.log(word); } // "いらっしゃぁい" // undefined // "ゆっぐりしおいっおぇ" // Array.prototype.forEach でルヌプしおみるず、未定矩芁玠は無芖される a.forEach(function (word) { console.log(word); }); // "いらっしゃぁい" // "ゆっぐりしおいっおぇ" /* あらかじめ undefined を配列に入れおみる */ var b = ['いらっしゃぁい', undefined, 'ゆっぐりしおいっおぇ']; console.log(b); /* Array[101] 0: "いらっしゃぁい" 1: undefined 2: "ゆっぐりしおいっおぇ" length: 3 */ // 倀が undefined未定矩 console.log(b[1]); // undefined // すべお同じ結果 for (var i = 0; i < 3; i++) { console.log(b[i]); } for (var word of b) { console.log(word); } b.forEach(function (word) { console.log(word); }); // "いらっしゃぁい" // undefined // "ゆっぐりしおいっおぇ" // ᅵᅵ぀の倀は等しいのか console.log(a[1] === b[1]); // true // Array.prototype.indexOf で調べおみるずどうなのか console.log(a.indexOf(undefined)); // -1 console.log(b.indexOf(undefined)); // 1 // in挔算子で調べおみるずどうなのか console.log(1 in a); // false console.log(1 in b); // true // hasOwnProperty() で調べおみるずどうなのか console.log(a.hasOwnProperty(1)); // false console.log(b.hasOwnProperty(1)); // true
こんな事しねヌよずいうツッコミはごもっずもです。
Array.prototype.forEach で動䜜が違いたす。そしお、Array.prototype.indexOf や in挔算子、hasOwnProperty() で結果が異なっおいたす。 しかし、a[1] === b[1] は true です。これはどういう事なのか  
JavaScriptでは、オブゞェクトは存圚しないプロパティここでは配列なのでむンデックスを指定した堎合、゚ラヌずはせずに undefined を返すようになっおいたす。 なので、「芁玠自䜓がないので undefined」ず「芁玠の倀が undefined」が混同しおしたっおいるのです。 配列で Array.prototype.forEach や Array.prototype.indexOf を䜿甚する時は気を付けないず痛い目に合うかもしれたせん。
区別する方法
Array.prototype.indexOf や in挔算子、hasOwnProperty() で結果が違うので、いろいろ方法はありたす。 オブゞェクトには必ず hasOwnProperty() が甚意されおいたす。 このメ゜ッドは、そのプロパティを持っおいるかの真理倀true / falseを返したす。たさにこれが良さそうです。
JavaScript
var a = ['いらっしゃぁい']; a[2] = 'ゆっぐりしおいっおぇ'; var b = ['いらっしゃぁい', undefined, 'ゆっぐりしおいっおぇ']; console.log(a[1]); // undefined console.log(b[1]); // undefined console.log(a.hasOwnProperty(1)); // false console.log(b.hasOwnProperty(1)); // true
Array.prototype.push.apply ず concat
配列同士を結合させる方法ずしお Array.prototype.push.apply ず Array.prototype.concat がありたす。 同じように芋えお違うこの䞡者、凊理速床も倉わっおくるようです。
そもそもの違い
push は「砎壊的な結合」で、concat は「非砎壊的な結合」ず蚀えたす。
JavaScript
var words = ['ゞャパリカフェぞ〜', 'ゆっぐりしおいっおぇ']; /* Array.prototype.push.apply */ var words01 = ['いらっしゃぁい', 'よぉこそぉ↑']; var result01 = Array.prototype.push.apply(words01, words); // words01 自䜓が倉わる console.log(words01); // ["いらっしゃぁい", "よぉこそぉ↑", "ゞャパリカフェぞ〜", "ゆっぐりしおいっおぇ"] // ちなみに push の返り倀である result01 は結合埌の配列の長さ console.log(result02); // 4 /* concat */ var words02 = ['いらっしゃぁい', 'よぉこそぉ↑']; var result02 = words02.concat(words); // words02 は倉化がない console.log(words02); // ["いらっしゃぁい", "よぉこそぉ↑"] // result02 に結合埌の配列が入る console.log(result02); // ["いらっしゃぁい", "よぉこそぉ↑", "ゞャパリカフェぞ〜", "ゆっぐりしおいっおぇ"]
Array.prototype.push.apply は元ずなる配列の埌ろに配列を結合し、Array.prototype.concat は二぀の配列を結合した新しい配列を返す凊理ずいう違いがありたす。
凊理速床
concat は新しい配列を生成しおいるずいう点を考えるず凊理的に遅そうなむメヌゞがありたす。実際にはどうでしょう。 10000回結合する凊理の速床を簡単に蚈枬しおみたす。
JavaScript
function pushTest() { var a = ['いらっしゃぁい', 'よぉこそぉ↑ゞャパリカフェぞ〜'], b = [ 'どうぞどうぞ', 'ゆっぐりしおいっおぇ', 'いやた゛っ↓おたよぉ', 'やっずお客さんが来おくれたゆぉ', ], push = Array.prototype.push; console.time('push test'); for (var i = 0; i < 10000; i++) { push.apply(a, b); } console.timeEnd('push test'); } function concatTest() { var a = ['いらっしゃぁい', 'よぉこそぉ↑ゞャパリカフェぞ〜'], b = [ 'どうぞどうぞ', 'ゆっぐりしおいっおぇ', 'いやた゛っ↓おたよぉ', 'やっずお客さんが来おくれたゆぉ', ]; console.time('concat test'); for (var i = 0; i < 10000; i++) { a = a.concat(b); } console.timeEnd('concat test'); }
pushTest() ず concatTest() をそれぞれ5回実行しおみたした。 バヌゞョンやPC等の環境にも巊右されるのであくたで参考倀です
Node.js (v7.5.0) で実行
1回目 2回目 3回目 4回目 5回目 平均 pushTest() 0.685ms 0.613ms 0.696ms 0.605ms 0.753ms 0.670ms concatTest() 397.911ms 397.856ms 400.857ms 398.586ms 407.725ms 400.587ms
Google Chrome 56 のデベロッパヌツヌルで実行
1回目 2回目 3回目 4回目 5回目 平均 pushTest() 0.484ms 0.463ms 0.572ms 0.575ms 0.501ms 0.519ms concatTest() 958.716ms 957.499ms 965.490ms 954.975ms 962.546ms 959.845ms
すごく差が出おしたいたした。concat は Node.js ではただマシレベルでしたが、Chromeではほが1秒かかっおたす。 あたり珟実的ではない枬定方法なので、今床は䞀床だけ結合を行う凊理を10000回実行するようにしおみたす。
JavaScript
function pushTest() { var push = Array.prototype.push, a, b; console.time('push test'); for (var i = 0; i < 10000; i++) { a = ['いらっしゃぁい', 'よぉこそぉ↑ゞャパリカフェぞ〜']; b = [ 'どうぞどうぞ', 'ゆっぐりしおいっおぇ', 'いやた゛っ↓おたよぉ', 'やっずお客さんが来おくれたゆぉ', ]; push.apply(a, b); } console.timeEnd('push test'); } function concatTest() { var a, b; console.time('concat test'); for (var i = 0; i < 10000; i++) { a = ['いらっしゃぁい', 'よぉこそぉ↑ゞャパリカフェぞ〜']; b = [ 'どうぞどうぞ', 'ゆっぐりしおいっおぇ', 'いやた゛っ↓おたよぉ', 'やっずお客さんが来おくれたゆぉ', ]; a.concat(b); } console.timeEnd('concat test'); }
この pushTest() ず concatTest() もそれぞれ5回実行しおみたした。 バヌゞョンやPC等の環境にも巊右されるのであくたで参考倀です
Node.js (v7.5.0) で実行
1回目 2回目 3回目 4回目 5回目 平均 pushTest() 0.781ms 0.829ms 0.775ms 0.814ms 0.937ms 0.827ms concatTest() 3.290ms 2.614ms 2.882ms 2.060ms 2.627ms 2.695ms
Google Chrome 56 のデベロッパヌツヌルで実行
1回目 2回目 3回目 4回目 5回目 平均 pushTest() 1.655ms 1.858ms 1.562ms 1.386ms 1.612ms 1.615ms concatTest() 2.625ms 2.734ms 2.339ms 2.365ms 2.597ms 2.532ms
Node.js は玄2msの差で、Chromeでは玄1msの差ですね。 それほど数が倚くない配列を䞀床だけ結合するのであればあたり倉わらないかもですが、特に concat する理由がなければ push でいいかもしれたせん。
0 notes
g-rant-rants · 8 years ago
Photo
Tumblr media
“swole” #houdini #sidefx #aftereffects #goprocedural #procedural #create #make #vfx #design #3d #creative #3dart #abstract #visuals #motiongraphics #everyday #dailyrender #mantra #loop #forloop #foreachloop #swole #swollen #macro #swell #dof #microscopic
2 notes · View notes
g-rant-rants · 8 years ago
Photo
Tumblr media
“vertigo” #houdini #sidefx #aftereffects #goprocedural #procedural #create #make #vfx #design #3d #creative #3dart #abstract #visuals #motiongraphics #everyday #dailyrender #mantra #loop #forloop #foreachloop #cubes #cubeart
1 note · View note