From ef887d11b450f4f821a46a37680aa7f70c59acdc Mon Sep 17 00:00:00 2001 From: yangzx18 Date: Wed, 15 May 2024 19:50:19 +0800 Subject: [PATCH 1/2] test: add performance test cases --- tester/svgDemoCases/App.tsx | 11 +- tester/svgDemoCases/Navigation.tsx | 11 +- tester/svgDemoCases/components/index.tsx | 6 +- .../components/performanceList.tsx | 337 ++++++++++++++++++ 4 files changed, 351 insertions(+), 14 deletions(-) create mode 100644 tester/svgDemoCases/components/performanceList.tsx diff --git a/tester/svgDemoCases/App.tsx b/tester/svgDemoCases/App.tsx index c55e1f0c..767ad222 100644 --- a/tester/svgDemoCases/App.tsx +++ b/tester/svgDemoCases/App.tsx @@ -7,12 +7,9 @@ import { StyleSheet, View, } from 'react-native'; -// import * as exampleByName from './components'; import {NavigationContainer, Page} from './Navigation'; -// import {Benchmarker, DeepTree, SierpinskiTriangle} from './benchmarks'; -import {PortalHost, PortalProvider} from '@gorhom/portal'; +import {PortalProvider} from '@gorhom/portal'; import testSuiteByName from './components'; -import {Tester} from '@rnoh/testerino'; const comList = Object.keys(testSuiteByName).map(testSuiteName => { @@ -38,12 +35,8 @@ function App() { return ( - {/* - */} + name={`${com.name}`}> - {/* - */} ); })} diff --git a/tester/svgDemoCases/Navigation.tsx b/tester/svgDemoCases/Navigation.tsx index 5e007ed5..055d21f6 100644 --- a/tester/svgDemoCases/Navigation.tsx +++ b/tester/svgDemoCases/Navigation.tsx @@ -22,10 +22,12 @@ const NavigationContext = React.createContext< export function NavigationContainer({ initialPage = 'INDEX', + hasHeader = true, children, }: { initialPage?: string; children: any; + hasHeader?: boolean }) { const [currentPageName, setCurrentPageName] = React.useState(initialPage); const [registeredPageNames, setRegisteredPageNames] = React.useState< @@ -49,7 +51,7 @@ export function NavigationContainer({ }}> - + {children} @@ -90,14 +92,14 @@ export function Page({name, children}: {name: string; children: any}) { ) : null; } -export function IndexPage() { +export function IndexPage({ hasHeader }: { hasHeader: boolean }) { const {navigateTo, registeredPageNames} = useNavigation(); return ( - RN Tester + RN Svg Capi Tester {'rnohArchitecture' in Platform.constants ? (` (${Platform.constants.rnohArchitecture})` as string) : ''} + : null } renderItem={({item}) => { return ( diff --git a/tester/svgDemoCases/components/index.tsx b/tester/svgDemoCases/components/index.tsx index b5e4bdad..a72be648 100644 --- a/tester/svgDemoCases/components/index.tsx +++ b/tester/svgDemoCases/components/index.tsx @@ -26,6 +26,7 @@ import ClipPath from './clipPath'; import Image from './Image'; import Combination from './Combination'; import ComplexDemo from './complexDemo'; +import PerformanceList from './PerformanceList'; export default { Circle, Defs, @@ -54,5 +55,8 @@ export default { ClipPath, Image, Combination, - ComplexDemo + ComplexDemo, + + + PerformanceTest: PerformanceList } \ No newline at end of file diff --git a/tester/svgDemoCases/components/performanceList.tsx b/tester/svgDemoCases/components/performanceList.tsx new file mode 100644 index 00000000..53515faa --- /dev/null +++ b/tester/svgDemoCases/components/performanceList.tsx @@ -0,0 +1,337 @@ + +import React from 'react'; +import { + SafeAreaView, + ScrollView, + StatusBar, + View, +} from 'react-native'; +import {NavigationContainer, Page} from '../Navigation'; +import {PortalProvider} from '@gorhom/portal'; +import { Circle, Svg, Ellipse, Path, Polygon, Polyline, Mask, Symbol, Text, Use, LinearGradient, RadialGradient, + TSpan, Image, G, Defs, ClipPath, Rect, Line, TextPath, Stop } from 'react-native-svg' +const testCount = 100 + +function repeat(com: React.ReactElement, repeatCount: number) { + const cases = [] + for(let i = 0; i < repeatCount; i++) { + cases.push( + ( + + { com } + + ) + ) + } + return cases +} + +const width = 100 +const height = 100 + +const CircleCase = ( + + + +) + +const EllipseCase = ( + + + +) + +const PathCase = ( + + + +) + +const PolygonCase = ( + + + +) + +const PolyLineCase = ( + + + +) + +const RectCase = ( + + + +) + +const LineCase = ( + + + +) + +const TextCase = ( + + + Test text with svg + + +) + +const DefsCase = ( + + + + + + + + + + +) + +const TextPathCase = ( + + + + + + Quick + 0brown fox jumps over the lazy dog. + + + +) + +const LinearGradientCase = ( + + + + + + + + + +) + +const RadialGradientCase = ( + + + + + + + + + +) + +const ClipPathCase = ( + + + + + + + + + + + +) + +const ImageCase = ( + + + +) + +const MaskCase = ( + + + + + + + + + +) + +const SymbolCase = ( + + + + + + + +) + + +interface ComInfo{ + name: string, + com: React.ReactElement +} + + +const comList: ComInfo[] = [ + { + name: 'Circle', + com: CircleCase + }, + { + name: 'Ellipse', + com: EllipseCase + }, + { + name: 'Path', + com: PathCase + }, + { + name: 'Polygon', + com: PolygonCase + }, + { + name: 'PolyLine', + com: PolyLineCase + }, + { + name: 'Rect', + com: RectCase + }, + { + name: 'Line', + com: LineCase + }, + { + name: 'Text & TSpan', + com: TextCase + }, + { + name: 'Defs & Use', + com: DefsCase + }, + { + name: 'TextPath', + com: TextPathCase + }, + { + name: 'LinearGradient & Stop', + com: LinearGradientCase + }, + { + name: 'RadialGradient & Stop', + com: RadialGradientCase + }, + { + name: 'ClipPath', + com: ClipPathCase + }, + { + name: 'Image', + com: ImageCase + }, + { + name: 'Mask', + com: MaskCase + }, + { + name: 'Symbol', + com: SymbolCase + } +] +// @ts-ignore +comList.sort((a, b) => { + return a.name.localeCompare(b.name) +}) + +function SingleComCase(TestCase: React.ReactElement, testCount: number) { + return ( + + + { repeat(TestCase, testCount) } + + + ) +} + +function AllComCase(comList: ComInfo[], testCount: number) { + const cases: React.ReactElement[] = [] + let i = 0 + while( cases.length < testCount) { + comList.forEach(com => { + cases.push( + ( + + { com.com } + + ) + ) + i++; + }) + } + return ( + + + { cases } + + + ) +} + + +function PerformanceList() { + return ( + + + + + + + { AllComCase(comList, testCount) } + + + {comList.map(com => { + const TestSuite = com.com + return ( + + { SingleComCase(TestSuite, testCount) } + + ); + })} + + + + + ); + } + export default PerformanceList \ No newline at end of file From 2c17e63c984d1a0b33ca444ca7b258b797555625 Mon Sep 17 00:00:00 2001 From: yangzx18 Date: Wed, 15 May 2024 20:01:23 +0800 Subject: [PATCH 2/2] test: add Pattern performance test --- .../components/performanceList.tsx | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tester/svgDemoCases/components/performanceList.tsx b/tester/svgDemoCases/components/performanceList.tsx index 53515faa..5581abca 100644 --- a/tester/svgDemoCases/components/performanceList.tsx +++ b/tester/svgDemoCases/components/performanceList.tsx @@ -9,8 +9,8 @@ import { import {NavigationContainer, Page} from '../Navigation'; import {PortalProvider} from '@gorhom/portal'; import { Circle, Svg, Ellipse, Path, Polygon, Polyline, Mask, Symbol, Text, Use, LinearGradient, RadialGradient, - TSpan, Image, G, Defs, ClipPath, Rect, Line, TextPath, Stop } from 'react-native-svg' -const testCount = 100 + TSpan, Image, G, Defs, ClipPath, Rect, Line, TextPath, Stop, Pattern } from 'react-native-svg' +const testCount = 1500 function repeat(com: React.ReactElement, repeatCount: number) { const cases = [] @@ -186,6 +186,22 @@ const SymbolCase = ( ) +const PatternCase = ( + + + + + + +) interface ComInfo{ name: string, @@ -257,6 +273,10 @@ const comList: ComInfo[] = [ { name: 'Symbol', com: SymbolCase + }, + { + name: 'Pattern', + com: PatternCase } ] // @ts-ignore