• 从入门开始手把手搭建千万级Java算法测试-主页面的搭建和自定义测试数组生成类


      从之前的文章当中,已经讲解了不少算法,其中这十个算法我们从算法思路,到算法伪代码实现,到复杂度分析,在进行学习后,已经拥有了搭建测试平台的基础,其中这个平台可以完你自身硬对算法从1000,到千万级测试,其中算法测试时间与你的机器硬件水平和实现的算法有关系,下面是怎么实现这个平台和自定义测试数组生产类的具体讲解,有了这些基础后添加后续的功能也十分的方便。

    下面是平台的具体实现:

    package runoob;
    import java.util.Scanner;
    
    public class main {
        public static class textSort{
            InsertionSort text=new InsertionSort();//插入排序
            SelectionSort text2=new SelectionSort();//选择排序
            ShellSort text3=new ShellSort();//希尔排序
            MergeSort text4=new MergeSort();//归并排序
            MergeSort text5=new MergeSort();//归并与插入比较(可以上列合并)
            Quick_sort text6=new Quick_sort();//快排+随机化快排
            Power_reckon text7=new Power_reckon();//n的幂指数
            Fibonacci text8=new Fibonacci();//斐波那契额数列的三种实现
            CountSort text9=new CountSort();//计数排序
            RandomSelect text10=new RandomSelect();//随机化查找第k大
            long num;
            int enter;
            public void enternum1(Scanner sc){
                enter=sc.nextInt();
            }
            public void enternum2(Scanner sc) {
                num=sc.nextInt();
            }
            public void CreatSort(){
    
                if (enter==1)
                    text.InsertionSort_text(num);
                else if(enter==2)
                    text2.SelectionSort_text(num);
                else if(enter==3)
                    text3.ShellSort_text(num);
                else if (enter==4)
                    text4.MergeSort_text(num);
                else if (enter==5)
                    text5.MergeSort_Incompear(num);
                else if (enter==6)
                    text6.Quicksort_text(num);
                else if (enter==7)
                    text7.reckon_text(num);
                else if(enter==8)
                    text8.Fibonacci_text(num);
                else if(enter==9)
                    text9.CountSort_text(num);
                else if(enter==10)
                    text10.RoandomSelect_text(num);
            }
        }
        public static void main(String[] args) {
            textSort text=new textSort();
            System.out.println("选择你需要算法"+"\n"+"1.插入排序"+"\n"+"2.选择排序"+"\n"+"3.希尔排序"+"\n"+"4.归并排序"+"\n"+"5.归并排序与插入比较"+"\n"+"6.快速排序与随机快速排序"+"\n"+"7.计算X的n次幂的两种方法"+"\n"+"8.斐波那契额数列的三种实现方法"+"\n"+"9.桶排序与快速排序的比较(常规快排)"+"\n"+"10.快速化排序与随机化查找第k个数");
            text.enternum1(new Scanner(System.in));
            System.out.println("请输入参与算法的数量");
            text.enternum2(new Scanner(System.in));
            text.CreatSort();
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57

    上述的算法具体实现参考往期文章:

    InsertionSort插入排序

    SelectionSort选择排序

    ShellSort希尔排序

    MergeSort归并排序

    MergeSort归并与插入比较(可以上列合并)

    Quick_sort快排+随机化快排

    Power_reckonn的幂指数的两种方法

    Fibonacci斐波那契额数列的三种实现

    CountSor计数排序

    RandomSelect随机化查找第k大数

    下列是实现的自定义测试数据的生成类,主要用于测试排序端口的数据生成和数据的打印:

      SortHelper类中的方法generateRandomArray的参数分别为,(num,left,right),其中第一个参数参与算法生成的数量级,由用户自行输入,参与算法的随机生成序列,它可以为千万级别,因为在其内部中属long级别,left和right则为生成序列的大小范围,生成的序列为返回值类型为Integer[]。
      SortHelper类中的方法printArray为无参方法,主要是方便打印操作。

    package runoob;
    
    
    import java.util.Scanner;
    
    public class SortHelper {
        // SortTestHelper不允许产生任何实例
        private SortHelper(){}
    
        // 生成有n个元素的随机数组,每个元素的随机范围为[rangeL, rangeR]
        public static Integer[] generateRandomArray(long n, int rangeL, int rangeR) {
    
            assert rangeL <= rangeR;
    
            Integer[] arr = new Integer[Math.toIntExact(n)];
    
            for (int i = 0; i < n; i++)
                arr[i] = new Integer((int)(Math.random() * (rangeR - rangeL + 1) + rangeL));
            System.out.println("下面为随机生成数列");
            printArray(arr);
            return arr;
        }
    
        // 打印arr数组的所有内容
        public static void printArray(Object arr[]) {
    
            for (int i = 0; i < arr.length; i++){
                System.out.print( arr[i] );
                System.out.print( ' ' );
            }
            System.out.println();
    
            return;
        }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    下列是运行结果:
    在这里插入图片描述
      可以直接选择测试的参与数据量的大小,然后根据算法内部的数据范围调整,生成对应的数据放入算法当中进行运行,其中包含测试时间和排序结果。
      下面是资源下载的地方,不想自己搭建的同学可以直接下载
    基于Java的千万级测试平台资源下载

  • 相关阅读:
    Service Mesh和Kubernetes:加强微服务的通信与安全性
    Excel函数公式大全—HLOOKUP函数
    链接装载与库:第六章——可执行文件的装载与进程
    C++学习 --pair
    delphi中使用CADVCL 10.0 Enterprise控件解析DXF文件生成图片保存到本地
    无法启动报,To install it, you can run: npm install --save @/components/iFrame/index
    Web APIs:事件高级--DOM事件流及DOM事件流程代码验证
    【平衡二叉搜索树】细撕AVL树的插入操作
    新库上线 | CnOpenData中国星级酒店数据
    vue3+element-plus props中的变量使用 v-model 报错
  • 原文地址:https://blog.csdn.net/qq_45764801/article/details/125443253