stress.rs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. use dioxus::prelude::*;
  2. use rand::prelude::*;
  3. fn main() {
  4. let mut dom = VirtualDom::new(app);
  5. _ = dom.rebuild();
  6. for _ in 0..1000 {
  7. _ = dom.rebuild();
  8. }
  9. }
  10. fn app(cx: Scope) -> Element {
  11. let mut rng = SmallRng::from_entropy();
  12. cx.render(rsx! (
  13. table {
  14. tbody {
  15. for f in 0..10_000_usize {
  16. table_row {
  17. row_id: f,
  18. label: Label::new(&mut rng)
  19. }
  20. }
  21. }
  22. }
  23. ))
  24. }
  25. #[derive(PartialEq, Props)]
  26. struct RowProps {
  27. row_id: usize,
  28. label: Label,
  29. }
  30. fn table_row(cx: Scope<RowProps>) -> Element {
  31. let [adj, col, noun] = cx.props.label.0;
  32. cx.render(rsx! {
  33. tr {
  34. td { class:"col-md-1", "{cx.props.row_id}" }
  35. td { class:"col-md-1", onclick: move |_| { /* run onselect */ },
  36. a { class: "lbl", "{adj}" "{col}" "{noun}" }
  37. }
  38. td { class: "col-md-1",
  39. a { class: "remove", onclick: move |_| {/* remove */},
  40. span { class: "glyphicon glyphicon-remove remove", aria_hidden: "true" }
  41. }
  42. }
  43. td { class: "col-md-6" }
  44. }
  45. })
  46. }
  47. #[derive(PartialEq)]
  48. struct Label([&'static str; 3]);
  49. impl Label {
  50. fn new(rng: &mut SmallRng) -> Self {
  51. Label([
  52. ADJECTIVES.choose(rng).unwrap(),
  53. COLOURS.choose(rng).unwrap(),
  54. NOUNS.choose(rng).unwrap(),
  55. ])
  56. }
  57. }
  58. static ADJECTIVES: &[&str] = &[
  59. "pretty",
  60. "large",
  61. "big",
  62. "small",
  63. "tall",
  64. "short",
  65. "long",
  66. "handsome",
  67. "plain",
  68. "quaint",
  69. "clean",
  70. "elegant",
  71. "easy",
  72. "angry",
  73. "crazy",
  74. "helpful",
  75. "mushy",
  76. "odd",
  77. "unsightly",
  78. "adorable",
  79. "important",
  80. "inexpensive",
  81. "cheap",
  82. "expensive",
  83. "fancy",
  84. ];
  85. static COLOURS: &[&str] = &[
  86. "red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black",
  87. "orange",
  88. ];
  89. static NOUNS: &[&str] = &[
  90. "table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger",
  91. "pizza", "mouse", "keyboard",
  92. ];