-
-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2511 from framer/feature/optimised-interpolate
Optimisations
- Loading branch information
Showing
40 changed files
with
891 additions
and
282 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<html> | ||
<!-- | ||
Mix unit value: Framer Motion | ||
This benchmark mixes simple unit values. | ||
--> | ||
<head> | ||
<style> | ||
body { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
.container { | ||
padding: 100px; | ||
width: 100%; | ||
display: flex; | ||
flex-wrap: wrap; | ||
} | ||
|
||
.container > div { | ||
width: 100px; | ||
height: 100px; | ||
} | ||
|
||
.box { | ||
width: 10px; | ||
height: 100px; | ||
background-color: #fff; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"></div> | ||
<script src="../../packages/framer-motion/dist/dom.js"></script> | ||
<script> | ||
const { mix } = window.Motion | ||
|
||
/** | ||
* Create an interpolate function that mixes unit values. | ||
*/ | ||
const mixer = mix( | ||
[100, "50vh", "100px", "#fff"], | ||
[0, "0vh", "0px", "#000"] | ||
) | ||
const numRuns = 1000000 | ||
let startTime = performance.now() | ||
for (let i = 0; i < numRuns; i++) { | ||
mixer(i / numRuns) | ||
} | ||
|
||
const finish = performance.now() - startTime | ||
console.log(`Total time: ${finish}ms`) | ||
</script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<html> | ||
<!-- | ||
Mix unit value: Framer Motion | ||
This benchmark mixes simple unit values. | ||
--> | ||
<head> | ||
<style> | ||
body { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
.container { | ||
padding: 100px; | ||
width: 100%; | ||
display: flex; | ||
flex-wrap: wrap; | ||
} | ||
|
||
.container > div { | ||
width: 100px; | ||
height: 100px; | ||
} | ||
|
||
.box { | ||
width: 10px; | ||
height: 100px; | ||
background-color: #fff; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"></div> | ||
<script src="../../node_modules/gsap/dist/gsap.js"></script> | ||
<script> | ||
/** | ||
* Create an interpolate function that mixes unit values. | ||
*/ | ||
const px = gsap.utils.interpolate( | ||
[100, 100, 100, 100], | ||
[0, 0, 0, 0] | ||
) | ||
|
||
const numRuns = 1000000 | ||
let startTime = performance.now() | ||
for (let i = 0; i < numRuns; i++) { | ||
px(i / numRuns) | ||
} | ||
console.log(`First run: ${performance.now() - startTime}ms`) | ||
</script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<html> | ||
<!-- | ||
Mix unit value: Framer Motion | ||
This benchmark mixes simple unit values. | ||
--> | ||
<head> | ||
<style> | ||
body { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
.container { | ||
padding: 100px; | ||
width: 100%; | ||
display: flex; | ||
flex-wrap: wrap; | ||
} | ||
|
||
.container > div { | ||
width: 100px; | ||
height: 100px; | ||
} | ||
|
||
.box { | ||
width: 10px; | ||
height: 100px; | ||
background-color: #fff; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"></div> | ||
<script src="../../packages/framer-motion/dist/dom.js"></script> | ||
<script> | ||
const { interpolate, mixColor } = window.Motion | ||
|
||
/** | ||
* Create an interpolate function that mixes unit values. | ||
*/ | ||
const mixer = interpolate( | ||
[0, 1], | ||
["rgba(255, 255, 255, 0)", "rgba(0, 0, 0, 0)"] | ||
) | ||
const numRuns = 10 | ||
let startTime = performance.now() | ||
for (let i = 0; i < numRuns; i++) { | ||
console.log(mixer(i / numRuns)) | ||
} | ||
|
||
const finish = performance.now() - startTime | ||
console.log(`Total time: ${finish}ms`) | ||
</script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<html> | ||
<!-- | ||
Mix unit value: Framer Motion | ||
This benchmark mixes simple unit values. | ||
--> | ||
<head> | ||
<style> | ||
body { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
.container { | ||
padding: 100px; | ||
width: 100%; | ||
display: flex; | ||
flex-wrap: wrap; | ||
} | ||
|
||
.container > div { | ||
width: 100px; | ||
height: 100px; | ||
} | ||
|
||
.box { | ||
width: 10px; | ||
height: 100px; | ||
background-color: #fff; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"></div> | ||
<script src="../../node_modules/gsap/dist/gsap.js"></script> | ||
<script> | ||
/** | ||
* Create an interpolate function that mixes unit values. | ||
*/ | ||
const px = gsap.utils.interpolate( | ||
"rgba(255, 255, 255, 0)", | ||
"rgba(0, 0, 0, 0)" | ||
) | ||
|
||
const numRuns = 10 | ||
let startTime = performance.now() | ||
for (let i = 0; i < numRuns; i++) { | ||
console.log(px(i / numRuns)) | ||
} | ||
console.log(`First run: ${performance.now() - startTime}ms`) | ||
</script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<html> | ||
<!-- | ||
Mix unit value: Framer Motion | ||
This benchmark mixes simple unit values. | ||
--> | ||
<head> | ||
<style> | ||
body { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
.container { | ||
padding: 100px; | ||
width: 100%; | ||
display: flex; | ||
flex-wrap: wrap; | ||
} | ||
|
||
.container > div { | ||
width: 100px; | ||
height: 100px; | ||
} | ||
|
||
.box { | ||
width: 10px; | ||
height: 100px; | ||
background-color: #fff; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"></div> | ||
<script src="../../packages/framer-motion/dist/dom.js"></script> | ||
<script> | ||
const { mix } = window.Motion | ||
|
||
/** | ||
* Create an interpolate function that mixes unit values. | ||
*/ | ||
const mixer = mix( | ||
"rgba(255, 255, 255, 0) 100px 40% 20px rgba(255, 255, 255, 0) var(--test) 67% 20vh 1vw", | ||
"rgba(0, 0, 0, 0) 0px 0% 100px rgba(255, 255, 255, 0) var(--test) 45% 0vh 1vw" | ||
) | ||
|
||
const numRuns = 100000 | ||
let startTime = performance.now() | ||
for (let i = 0; i < numRuns; i++) { | ||
mixer(i / numRuns) | ||
} | ||
|
||
const finish = performance.now() - startTime | ||
console.log(`Total time: ${finish}ms`) | ||
</script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<html> | ||
<!-- | ||
Mix unit value: Framer Motion | ||
This benchmark mixes simple unit values. | ||
--> | ||
<head> | ||
<style> | ||
body { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
.container { | ||
padding: 100px; | ||
width: 100%; | ||
display: flex; | ||
flex-wrap: wrap; | ||
} | ||
|
||
.container > div { | ||
width: 100px; | ||
height: 100px; | ||
} | ||
|
||
.box { | ||
width: 10px; | ||
height: 100px; | ||
background-color: #fff; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"></div> | ||
<script src="../../node_modules/gsap/dist/gsap.js"></script> | ||
<script> | ||
/** | ||
* Create an interpolate function that mixes unit values. | ||
*/ | ||
const px = gsap.utils.interpolate( | ||
"rgba(255, 255, 255, 0) 100px 40% 20px rgba(255, 255, 255, 0) var(--test) 67% 20vh 1vw", | ||
"rgba(0, 0, 0, 0) 0px 0% 100px rgba(255, 255, 255, 0) var(--test) 45% 0vh 1vw" | ||
) | ||
|
||
const numRuns = 10 | ||
let startTime = performance.now() | ||
for (let i = 0; i < numRuns; i++) { | ||
px(i / numRuns) | ||
} | ||
console.log(`First run: ${performance.now() - startTime}ms`) | ||
</script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<html> | ||
<!-- | ||
Mix unit value: Framer Motion | ||
This benchmark mixes simple unit values. | ||
--> | ||
<head> | ||
<style> | ||
body { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
.container { | ||
padding: 100px; | ||
width: 100%; | ||
display: flex; | ||
flex-wrap: wrap; | ||
} | ||
|
||
.container > div { | ||
width: 100px; | ||
height: 100px; | ||
} | ||
|
||
.box { | ||
width: 10px; | ||
height: 100px; | ||
background-color: #fff; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"></div> | ||
<script src="../../packages/framer-motion/dist/dom.js"></script> | ||
<script src="../../node_modules/gsap/dist/gsap.min.js"></script> | ||
<script> | ||
const { mix } = window.Motion | ||
|
||
/** | ||
* Create an interpolate function that mixes unit values. | ||
*/ | ||
const px = mix(0, 100) | ||
|
||
const numRuns = 100000000 | ||
let startTime = performance.now() | ||
for (let i = 0; i < numRuns; i++) { | ||
px(i / numRuns) | ||
} | ||
console.log(`First run: ${performance.now() - startTime}ms`) | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.