stress.rs 2.1 KB

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