{"action":"created","issue":{"url":"https://api.github.com/repos/HaxeFlixel/flixel/issues/1770","repository_url":"https://api.github.com/repos/HaxeFlixel/flixel","labels_url":"https://api.github.com/repos/HaxeFlixel/flixel/issues/1770/labels{/name}","comments_url":"https://api.github.com/repos/HaxeFlixel/flixel/issues/1770/comments","events_url":"https://api.github.com/repos/HaxeFlixel/flixel/issues/1770/events","html_url":"https://github.com/HaxeFlixel/flixel/pull/1770","id":139645785,"number":1770,"title":"Add FlxMath.fastFloor()","user":{"login":"MSGhero","id":5033927,"avatar_url":"https://avatars.githubusercontent.com/u/5033927?v=3","gravatar_id":"","url":"https://api.github.com/users/MSGhero","html_url":"https://github.com/MSGhero","followers_url":"https://api.github.com/users/MSGhero/followers","following_url":"https://api.github.com/users/MSGhero/following{/other_user}","gists_url":"https://api.github.com/users/MSGhero/gists{/gist_id}","starred_url":"https://api.github.com/users/MSGhero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MSGhero/subscriptions","organizations_url":"https://api.github.com/users/MSGhero/orgs","repos_url":"https://api.github.com/users/MSGhero/repos","events_url":"https://api.github.com/users/MSGhero/events{/privacy}","received_events_url":"https://api.github.com/users/MSGhero/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/HaxeFlixel/flixel/labels/Improvement","name":"Improvement","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/HaxeFlixel/flixel/milestones/8","html_url":"https://github.com/HaxeFlixel/flixel/milestones/4.1.0","labels_url":"https://api.github.com/repos/HaxeFlixel/flixel/milestones/8/labels","id":1556723,"number":8,"title":"4.1.0","description":"","creator":{"login":"Gama11","id":2620907,"avatar_url":"https://avatars.githubusercontent.com/u/2620907?v=3","gravatar_id":"","url":"https://api.github.com/users/Gama11","html_url":"https://github.com/Gama11","followers_url":"https://api.github.com/users/Gama11/followers","following_url":"https://api.github.com/users/Gama11/following{/other_user}","gists_url":"https://api.github.com/users/Gama11/gists{/gist_id}","starred_url":"https://api.github.com/users/Gama11/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gama11/subscriptions","organizations_url":"https://api.github.com/users/Gama11/orgs","repos_url":"https://api.github.com/users/Gama11/repos","events_url":"https://api.github.com/users/Gama11/events{/privacy}","received_events_url":"https://api.github.com/users/Gama11/received_events","type":"User","site_admin":false},"open_issues":11,"closed_issues":6,"state":"open","created_at":"2016-02-01T20:44:15Z","updated_at":"2016-03-09T19:06:27Z","due_on":null,"closed_at":null},"comments":18,"created_at":"2016-03-09T17:23:38Z","updated_at":"2016-03-11T14:57:51Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/HaxeFlixel/flixel/pulls/1770","html_url":"https://github.com/HaxeFlixel/flixel/pull/1770","diff_url":"https://github.com/HaxeFlixel/flixel/pull/1770.diff","patch_url":"https://github.com/HaxeFlixel/flixel/pull/1770.patch"},"body":"It kinda looks like the function call to `Math.floor` takes longer than actually flooring on js. `fastFloor` was about 20x faster in my little test suite with analyzer off.\r\n\r\nNot sure if there's a `fastCeil`. I was also thinking about using `fastSin` and `fastCos` throughout the library, but that's technically a breaking change?"},"comment":{"url":"https://api.github.com/repos/HaxeFlixel/flixel/issues/comments/195400670","html_url":"https://github.com/HaxeFlixel/flixel/pull/1770#issuecomment-195400670","issue_url":"https://api.github.com/repos/HaxeFlixel/flixel/issues/1770","id":195400670,"user":{"login":"Gama11","id":2620907,"avatar_url":"https://avatars.githubusercontent.com/u/2620907?v=3","gravatar_id":"","url":"https://api.github.com/users/Gama11","html_url":"https://github.com/Gama11","followers_url":"https://api.github.com/users/Gama11/followers","following_url":"https://api.github.com/users/Gama11/following{/other_user}","gists_url":"https://api.github.com/users/Gama11/gists{/gist_id}","starred_url":"https://api.github.com/users/Gama11/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gama11/subscriptions","organizations_url":"https://api.github.com/users/Gama11/orgs","repos_url":"https://api.github.com/users/Gama11/repos","events_url":"https://api.github.com/users/Gama11/events{/privacy}","received_events_url":"https://api.github.com/users/Gama11/received_events","type":"User","site_admin":false},"created_at":"2016-03-11T14:57:51Z","updated_at":"2016-03-11T14:57:51Z","body":"I did a bit of benchmarking (debug build). According to these results, `fastFloor()` is __slower on all targets__ (considerably even on Neko and CPP). It gets better with inline, but `fastFloor()` only beats `Math.floor()` on Flash, by a factor of ~2.\r\n\r\n|       | Math.floor() | FlxMath.fastFloor() | inline FlxMath.fastFloor() |\r\n|-------|--------------|---------------------|----------------------------|\r\n| **Flash** | 0.127s       | 0.183s              | 0.066s                     |\r\n| **HTML5** | 0.001s       | 0.002s              | 0.002s                     |\r\n| **Neko**  | 0.0267s      | 0.0819s             | 0.0573s                    |\r\n| **CPP**  | 0.0202s      | 0.368s              | 0.194s                     |\r\n\r\n```haxe\r\npackage;\r\n\r\nimport flixel.FlxState;\r\nimport haxe.Timer;\r\n\r\nclass PlayState extends FlxState\r\n{\r\n\toverride public function create():Void\r\n\t{\r\n\t\tTimer.measure(testMathFloor);\r\n\t\tTimer.measure(testFastFloor);\r\n\t\tTimer.measure(testFastFloorInline);\r\n\t}\r\n\r\n\tfunction testMathFloor()\r\n\t{\r\n\t\tfor (i in -500000...500000)\r\n\t\t\tMath.floor(i);\r\n\t}\r\n\r\n\tfunction testFastFloor()\r\n\t{\r\n\t\tfor (i in -500000...500000)\r\n\t\t\tfastFloor(i);\r\n\t}\r\n\r\n\tfunction testFastFloorInline()\r\n\t{\r\n\t\tfor (i in -500000...500000)\r\n\t\t\tinlineFastFloor(i);\r\n\t}\r\n\t\r\n\tfunction fastFloor(f:Float):Int\r\n\t{\r\n\t\treturn f >= 0 ? Std.int(f) : Std.int(f - 1);\r\n\t}\r\n\r\n\tinline function inlineFastFloor(f:Float):Int\r\n\t{\r\n\t\treturn f >= 0 ? Std.int(f) : Std.int(f - 1);\r\n\t}\r\n}\r\n```\r\n\r\n@MSGhero I'm curious why my results are so different from yours - what does you code look like?"}}